Trolley
Trolley

Reputation: 2414

Phonegap change language of labels?

I have a Phonegap app, where I use the camera plugin. The problem is, that the buttons doesn't use the native iOS language, instead they're only english ('Retake' and 'Use' etc.).

The app I'm doing is an app for children, but they're not native english speakers. So I would like to have it in their native language.

Is there any way I can translate those buttons into the correct language?

Upvotes: 6

Views: 4433

Answers (6)

Paranoid Android
Paranoid Android

Reputation: 5037

The solution is to declare the languages in your plist file like:

<key>CFBundleLocalizations</key> <array> <string>it</string> <string>es</string> </array>

If you do not want to do it manually, because you are likely not tracking the plist file, you could use the Cordova Custom Config plugin to add the missing keys to your plist file when you run cordova prepare

Upvotes: 0

Djames
Djames

Reputation: 502

If you don't want to manually change the language in XCode after each build, you can do the following updates in the phonegap/cordova source code on your Mac :

(Example with cordova 3.6.3 and French locale, you need to update to your version & language)

Folder : ~\.cordova\lib\npm_cache\cordova-ios\3.6.3\package\bin\templates\project\__PROJECT_NAME__\
File : __PROJECT_NAME__-Info.plist
Update :
    => Change <key>CFBundleDevelopmentRegion</key>
              <string>English</string>
       to     <key>CFBundleDevelopmentRegion</key>
              <string>France</string>

    => Add after it
              <key>CFBundleLocalizations</key>
              <array>
                    <string>fr</string>
              </array>

Folder : ~\.cordova\lib\npm_cache\cordova-ios\3.6.3\package\bin\templates\project\__PROJECT_NAME__\Resources\
Update :
    => Create a 'fr.lproj' folder by Copy/Paste of the 'en.lproj' folder
    => Complete the translation in 'fr.lproj/Localizable.strings' file (not required)

This will affect all the projects that you build with this cordova version.

Backup your cordova folder before and don't leave unwanted files under the 'templates' folder or they will be copied in the final package.

Hope it helps.

Upvotes: 1

Javier Zarza
Javier Zarza

Reputation: 21

In fact, CFBundleDevelopentRegion seems to be a fallback if iOS can't find localizations declared in the CFBundleLocalizations.

You don't need to change that key. Just adding array of ISO country codes in .plist (as Michaël did) it's enough.

Upvotes: 0

Micha&#235;l Witrant
Micha&#235;l Witrant

Reputation: 7714

I was able to change the label languages by modifying the project plist (platforms/ios/ProjectName/ProjectNAme-Info.plist).

I changed CFBundleDevelopmentRegion from English to fr_FR and added this array:

<key>CFBundleLocalizations</key>
<array>
  <string>fr</string>
</array>

Upvotes: 2

luizs81
luizs81

Reputation: 397

If you are using XCode as IDE to develop your project, you can localize it as a normal iOS project. To know how do that you can check in this other post. You will not need to provide the translation for those "words" (Retake, Use and etc), just setting the proper localizations will tell the iOS to use the native language.

But, if you are using PhoneGap Build to compile your project, check this topic in the PhoneGap Build forum. Similar with the XCode procedure, you will need to create a folder called "locales" under your /www directory and put there the languages you want use. Again, you don't need to provide the translation for that buttons. The iOS will do by itself.

Upvotes: 1

poiuytrez
poiuytrez

Reputation: 22518

Cordova is fortunately open source.
The first step is to report the bug on the Apache Cordova bug tracker. Then, clone the cordova source code to try to understand why the plugin does not display the correct language.

It is not so complicated. Plugins a just a glue between a javascript function and a native function.

Upvotes: 0

Related Questions