GithubHelp home page GithubHelp logo

shizu2014 / ghllocalizable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhangkn/ghllocalizable

0.0 1.0 0.0 61 KB

iOS 应用内语言设置工具

License: MIT License

Objective-C 94.72% Ruby 5.28%

ghllocalizable's Introduction

GHLLocalizable

iOS 应用内语言设置工具

Packagist CocoaPods Travis Build Status

Demo

请查看 Example/GHLLocalizable.xcodeproj 目录下示例工程

使用方法

默认你已经完成了对工程本地化语言的配置,如果没有,请参考我的博客文章:GHLLocalizable:iOS应用内语言设置工具

1、初始化该工具类,比如在 AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法里:

[GHLLocalizableController initUserLanguage];

2、更改语言方法:

// 设置中文
[GHLLocalizable setUserlanguage:GHLChinese_Hans];

// 设置英文
[GHLLocalizable setUserlanguage:GHLEnglish];

3、使用 NSLocalizedString(<#key#>, <#comment#>)方法 给所有文字添加本地化语言方法:

label.text = NSLocalizedString(@"这是一段本地化语言的文字", nil);

4、监听语言更改通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChange:) name:GHLNotificationLanguageChanged object:nil];

记得删除通知,比如在 - (void)applicationWillTerminate:(UIApplication *)application方法里:

[[NSNotificationCenter defaultCenter] removeObserver:self name:GHLNotificationLanguageChanged object:nil];

5、实现通知方法:

- (void)languageChange:(NSNotification *)note {
    // 在该方法里实现重新初始化 rootViewController 的行为,并且所有带有文字的页面都要重新渲染
    // 比如:[UIApplication sharedApplication].keyWindow.rootViewController = ...;
}

安装

CocoaPods

  1. 添加 pod 'GHLLocalizable' 命令到你的 Podfile 文件。
  2. 执行 pod install 方法,或者 pod update 方法。
  3. 引用 <GHLLocalizable/GHLLocalizable.h> 头文件。

手动安装

  1. 下载 GHLLocalizable 目录下的所有文件。
  2. 添加这些源文件到你的工程里。
  3. 引用 GHLLocalizable.h 头文件。

License

GHLLocalizable is provided under the MIT license. See LICENSE file for details.

ghllocalizable's People

Contributors

gonghonglou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.