Currently, I have three separate .strings
files - for English, French and German respectively.
I have a UISegmentedControl
in the preferences section, where I would like to change the default .strings
file used depending on which segment is selected.
Localisation is already working outside the application when I test it, and I've even managed to localise individual objects depending on which segment is selected (If france is selected, the label text below changes from "South" to "Sud", and then back again if English is re-selected) using this:
if(German segment) {
NSString *path= [[NSBundle mainBundle] pathForResource:@"de" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
// Returns german version of localised string as label text.
self.defaultName.titleLabel.text = [languageBundle localizedStringForKey:@"PREF_WEATHER_NORTH" value:@"" table:nil];
// I would like to set the default .strings file to 'de' here.
}
else if(French segment) {
NSString *path= [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
// Returns french version of localised string as label text
self.defaultName.titleLabel.text = [languageBundle localizedStringForKey:@"PREF_WEATHER_NORTH" value:@"" table:nil];
// I would like to set the default .strings file to 'fr' here
}
else if(British segment) {
NSString *path= [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
// Returns english version of localised string as label text
self.defaultName.titleLabel.text = [languageBundle localizedStringForKey:@"PREF_WEATHER_NORTH" value:@"" table:nil];
// I would like to set the default .strings file to 'en' here.
}
Now, as I've already got individual strings being localised on button click, I was wondering if I could localise ALL strings in each of the .strings
files in one go (so that I'm changing the default .strings used depending on which segment is selected) or at least target as many as possible in an acceptable amount of code.
Obviously, at the moment I could type them one-by-one, but that isn't really an option due to the amount of localised strings used in an application.
Any help would be appreciated.