Last active
December 14, 2015 21:28
-
-
Save lamprosg/5151359 to your computer and use it in GitHub Desktop.
(iOS) Localization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Localization folders have the format | |
| fr_FR.lproj -> ISOLanguage_ISOCountryCode.lproj | |
| Second try, will search: fr.lproj | |
| Third try, will search: fre.lproj | |
| -------------------- | |
| String Files: | |
| Named "Localizable.strings" and will be in each localization folder (in the finder - ex. en.lproj fr.lproj) | |
| //In the project thre will be at first 1 file that we'll have to localize for each language and edit each | |
| Strings to the left act as keys, and strings to the right as the translated valye | |
| //Localizable.strings (English) | |
| /* Used to ask the user his/her first name */ | |
| "LABEL_FIRST_NAME" = "First Name"; | |
| //Localizable.strings (French) | |
| /* Used to ask the user his/her first name */ | |
| "LABEL_FIRST_NAME " = "Prénom" | |
| -------------------- | |
| Using String Files | |
| NSLocalizedString looks in the application bundle inside the appropriate localization project | |
| for a strings file named localizable.strings | |
| //First parameter is the key, the 2d is the comment | |
| NSString *myString = NSLocalizedString(@"LABEL_FIRST_NAME", | |
| @"Used to ask the user his/her first name"); | |
| //If there is no localization (doesn't find the file) it will return the 1st string | |
| ------------------- | |
| //NSLocale works somewhat like a dictionary. | |
| //It can give you a whole bunch of information about the current user’s preferences, | |
| //including the name of the currency and the expected date format. | |
| NSLocale *locale = [NSLocale currentLocale]; | |
| //Retrieve language/region of the user (en_US, fr_FR etc) | |
| //displayNameForKey:value: returns the value that we requested in a specific language | |
| NSString *displayNameString = [locale | |
| displayNameForKey:NSLocaleIdentifier | |
| value:[locale localeIdentifier]]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment