What is it?
MRGLocale gives you 2 super features:
- Change the preferred language in-app
- Update your localizations without building your app
How to use it
First things first
pod installin your terminal at the root of your project
Use it for real
Since the pod is installed, you no longer use
Changing preferred language
[[MRGLocale sharedInstance] setLanguageBundleWithLanguageISO639Identifier:@"fr_CA"];
Updating your localizations dynamically
Say you want to update your localizations with a file on S3:
MRGRemoteStringFile *remoteStringFile = [[MRGRemoteStringFile alloc] initWithLanguageIdentifier:@"en" url:[NSURL URLWithString:@"https://bucket.s3.amazonaws.com/Localizables.json"]; [[MRGLocale sharedInstance] setRemoteStringResourceList:@[remoteStringFile]];
The code above creates your remote string resources for your updatable localizations. In order to check for updates, you only need to periodically call the following method:
[[MRGLocale sharedInstance] refreshRemoteStringResourcesWithCompletion:completionBlock];
- (void)applicationDidBecomeActive:(UIApplication *)application in the app delegate would be a great place. The updates will only be available after you kill and restart the app.
Creating a customized "Remote String Resource" for your customized API
Create a class that conforms to the
MRGRemoteStringResource protocol. Long story short, it needs to implement:
- (NSString *)languageIdentifier; - (NSData *)fetchRemoteResource:(NSError **)error;
If a translation is not available from the remote string resource,
MRGLocale will fallback to the app bundle's
Converting an old project to MRGLocale
In Xcode, use the regular expression feature of find and replace all to convert occurences of
NSLocalizedString\(@"([^\)"]*)"([^\)]*)\)and "replace" with
NSLocalizedStringFromTable\(@"([^\)"]*)",( )?@"([^\)"]*)"([^\)]*)\)and "replace" with
NSLocalizedStringWithDefaultValue are currently not supported by
If you're using MRGLocale in a Watch or an App Extension, make sure you link against the
MRGLocale/Core subspec so it doesn't link the MRGControlPanel as well (it uses API like UIAlertView and UIApplication's sharedApplication methods that are not allowed in an extension).
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.
We also love open-source software and we try to give back to the community as much as we can.