4
votes

I'm using the stringsdict functionality in an iOS app for localization. The app is in English and being localized to French. Therefore I have an English version as base and a French one for translations.

If as a user i have my language set to a different one such as Spanish the app correctly uses the base localization (English). However, suppose i have an item in my base stringsdict that doesn't exist in the French one. Here the string will come out as just the key (i.e not looked up from a stringsdict file). Is there a way to fallback to the base stringsdict on a key by key basis? As opposed to only when that locales stringsdict doesn't exist.

1

1 Answers

0
votes

You can wrap NSLocalizedString and compare the value to the key. If it is the key you can grab the translation out of a fallback.strings file out of the bundle.

- (NSString *)localizedStringForKey:(NSString *)key value:(nullable NSString *)value table:(nullable NSString *)tableName NS_FORMAT_ARGUMENT(1);

The other option is to start off with a duplicate of the English file for your translation file and replace them piecemeal.

Neither of these are ideal. But the wrapping option scales better and will help you with dialects in the future.