All Projects → maximbilan → Language Manager Ios

maximbilan / Language Manager Ios

Licence: mit
Language Manager iOS

Programming Languages

language
365 projects
languages
34 projects

Projects that are alternatives of or similar to Language Manager Ios

SwiftGenStrings
genstrings replacement for Swift that actually works
Stars: ✭ 29 (-86.94%)
Mutual labels:  apple, localization
Hackintosh Installer University
Open source tutorial & information collector for hackintosh installation.
Stars: ✭ 3,815 (+1618.47%)
Mutual labels:  apple, tutorial
Arshooter
A demo Augmented Reality shooter made with ARKit in Swift (iOS 11)
Stars: ✭ 794 (+257.66%)
Mutual labels:  apple, tutorial
Material Onboarding
A simple library which allows easy replication of several* app onboarding techniques.
Stars: ✭ 217 (-2.25%)
Mutual labels:  tutorial
How To Read Pytorch
Quick, visual, principled introduction to pytorch code through five colab notebooks.
Stars: ✭ 218 (-1.8%)
Mutual labels:  tutorial
Knative Tutorial
https://dn.dev/master A practical guide to get started with Knative. Knative concepts are explained simple and easy way with lots of demos and exercises.
Stars: ✭ 219 (-1.35%)
Mutual labels:  tutorial
Way To Algorithm
Algorithm Tutorial and Source Code
Stars: ✭ 221 (-0.45%)
Mutual labels:  tutorial
Tensorflow
Deep Learning Zero to All - Tensorflow
Stars: ✭ 216 (-2.7%)
Mutual labels:  tutorial
Stealthgameudemy
C++ Stealth Game in Unreal Engine (Udemy Project)
Stars: ✭ 221 (-0.45%)
Mutual labels:  tutorial
Bit Preserve
Project for capturing vintage, classic, aka old computer schematics in KiCad.
Stars: ✭ 219 (-1.35%)
Mutual labels:  apple
Modern Graphql Tutorial
📖 A simple and easy GraphQL tutorial to get started with GraphQL.
Stars: ✭ 219 (-1.35%)
Mutual labels:  tutorial
Iris lama
LaMa - A Localization and Mapping library
Stars: ✭ 217 (-2.25%)
Mutual labels:  localization
Awesome Powershell
A curated list of delightful PowerShell modules and resources
Stars: ✭ 2,967 (+1236.49%)
Mutual labels:  tutorial
Notificato
Takes care of Apple push notifications (APNS) in your PHP projects.
Stars: ✭ 217 (-2.25%)
Mutual labels:  apple
Dl For Chatbot
Deep Learning / NLP tutorial for Chatbot Developers
Stars: ✭ 221 (-0.45%)
Mutual labels:  tutorial
Test Repo
This is a test repo, please fork me !!! \(^_^)/
Stars: ✭ 217 (-2.25%)
Mutual labels:  tutorial
React Native Header View
Fully customizable Header View with multiple design options for React Native.
Stars: ✭ 221 (-0.45%)
Mutual labels:  apple
Rules apple
Bazel rules to build apps for Apple platforms.
Stars: ✭ 217 (-2.25%)
Mutual labels:  apple
Townhouse
A multi-tenant Laravel app for listing property rentals
Stars: ✭ 218 (-1.8%)
Mutual labels:  tutorial
Howtodothisinflutter
📄Flutter cheat sheet
Stars: ✭ 219 (-1.35%)
Mutual labels:  tutorial

How to change localization internally in your iOS application

Unfortunately, there’s no official way provided by Apple for this purpose. Let’s look at two methods for solving this problem.

Method #1

Apple provides a way to specify an application-specific language, by updating the “AppleLanguages” key in NSUserDefaults. For example:

[[NSUserDefaults standardUserDefaults] setObject:@"fr" forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

For working this method, you’ll have to set it before UIKit initialized.

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "LanguageManager.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        [[NSUserDefaults standardUserDefaults] setObject:@"fr" forKey:@"AppleLanguages"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

The problem of this method is that the app has to be relaunched to take effect.

Method #2

The solution is to swap the mainBundle of our application as soon as the user changes their language preferences inside the app.

See the category for NSBundle.

Header:

#import <Foundation/Foundation.h>

@interface NSBundle (Language)

+ (void)setLanguage:(NSString *)language;

@end

Implementation:

#import "NSBundle+Language.h"
#import <objc/runtime.h>

static const char kBundleKey = 0;

@interface BundleEx : NSBundle

@end

@implementation BundleEx

- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
{
    NSBundle *bundle = objc_getAssociatedObject(self, &kBundleKey);
    if (bundle) {
        return [bundle localizedStringForKey:key value:value table:tableName];
    }
    else {
        return [super localizedStringForKey:key value:value table:tableName];
    }
}

@end

@implementation NSBundle (Language)

+ (void)setLanguage:(NSString *)language
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        object_setClass([NSBundle mainBundle],[BundleEx class]);
    });
    id value = language ? [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]] : nil;
    objc_setAssociatedObject([NSBundle mainBundle], &kBundleKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end

In this method, a problem that may arise is updating elements on active screens. You can reload your rootViewController from our application delegate, will always work reliably.

- (void)reloadRootViewController
{
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    NSString *storyboardName = @"Main";
    UIStoryboard *storybaord = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
    delegate.window.rootViewController = [storybaord instantiateInitialViewController];
}

All code you can see in this repository. With a simple example.

alt tag

Please, use for free and like it ☺.

Note: In the example project by default the app uses method #2. You can disable this. Just comment define USE_ON_FLY_LOCALIZATION.

More details on the blog here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].