XCode PhoneGap Localization

2019-06-27 00:52发布

问题:

I have been banging my head against the wall for 2 days trying add language-specific localization to my app. The App is using PhoneGap 1.1 and I am trying to build it up using XCode 4.1

I have been searching for infos/tutorial/whatever since 2 days now but I could not find anything detailed. So, either it's a trivial issue and I am failing at understing it, or it's an uncommon issue.

Many threads I've seen explain that I have to create a new folder under "Resources" and add the following folders to the project (say I want my app to be localized in French and for non-French speaking countries):

--locales

--- en

---- local.strings

--- fr

---- local.strings

I am already in troubles now: first of all, what should I consider as my project root folder? All my code is inside the "www" folder and as far as I understood, this is the main node PG looks at when doing its job. So I assume I have to create "locales" under "www".

Assuming this is the correct place, I have to enter the key-value pairs into the .strings file. Now, how do I tell Xcode which strings it needs to look at in my index.html page? In Objective-C this is done by calling NSLocalizedString(@"StringKey"), but since I am using PG I have either plain HTML or JS to use. Is there any built-in method to do so?

Is this the wrong approach? Any hint, tutorial, documentation, reference guide on the subject would be of great help.

回答1:

PhoneGap is organized in a different way.

The www/index.html file is loaded as a webView from within the DroidGap class. This is, at least from my understanding, the only point (besides a Javascript Plugin) where you could intercept the loading of the html page and apply any localization parsing. Once the www/index.html is rendered, any further links are either processed internally (multi-page approach) or via links to "external" (single page approach) html pages.

If no Javascript Callback method is reached, no PhoneGap backend classes and thus no iOS specific classes are called and processed.

PhoneGap plugins provide a Javascript-Bridge to the native coding environment and can thus be used to provide localization.

Just found a thread which might help:

http://community.phonegap.com/nitobi/topics/problem_with_binary_details_ios_localization_builded_with_phonegap_build?from_gsfn=true