Git Product home page Git Product logo

languagemanager-ios's Introduction


A Language manager to handle changing app language without restarting the app.


ScreenShots

LanguageManager-SwiftUI

For SwiftUI please visit the LanguageManager-SwiftUI

LanguageManager-iOS + Lokalise

For LanguageManger-iOS with Lokalise integration please visit the LanguageManager-iOS-Lokalise repo.

Usage

Youtube: iOS - Support multiple languages (Localization).
Watch the video

First of all, remember to add the Localizable.strings to your project, after adding the Localizable.strings file, select it then go to file inspector and below localization press localize, after that go to PROJECT > Localisation then add the languages you want to support (Arabic for example), dialog will appear to ask you which resource file you want to localize, select just the Localizable.strings file.
 
Now, go to your storyboard and add UILable and add text to it, for example "Hello !", then go to your Localizable.strings file expand it, you will find Localizable strings file for English and Arabic, for English put just this line with the string you put in the UILabel inside the storyboard
"Hello !" = "Hello !";
and for Arabic file :
"Hello !" = "مرحبا !";


After that in didFinishLaunchingWithOptions inside the AppDelegate.swift set your default language that your app will run first time
LanguageManager.shared.defaultLanguage = .en // you can use .deviceLanguage to keep the device language.

If you want to change the language use the setLanguage(language:) method by passing to it the new language

  @IBAction func changeLanguage(_ sender: UIButton) {

    let selectedLanguage: Languages = sender.tag == 1 ? .en : .ar

    // change the language
    LanguageManager.shared.setLanguage(language: selectedLanguage)
    { title -> UIViewController in
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
      // the view controller that you want to show after changing the language
      return storyboard.instantiateInitialViewController()!
    } animation: { view in
      // do custom animation
      view.transform = CGAffineTransform(scaleX: 2, y: 2)
      view.alpha = 0
    }
  }

If you have an image and you want to change the direction of the image depending on the language, you can use image direction property, the property can be one of the following values:

-fixed: if the image must not change the direction depending on the language, you need to set the value as 0.

-leftToRight: if the image must change the direction depending on the language and the image is left to right image then you need to set the value as 1.

-rightToLeft: if the image must change the direction depending on the language and the image is right to left image then you need to set the value as 2.

Please check the example project to see how it works.

Installation

LanguageManager-iOS is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LanguageManager-iOS'

Or you can use Carthage.

github "Abedalkareem/LanguageManager-iOS"

You can also use Swift Package Manager.

Support me 🚀

You can support this project by:

1- Checking my apps.
2- Star the repo.
3- Share the repo with your friends.

Follow me ❤️

Facebook | Twitter | Instagram | Youtube

License

The MIT License (MIT)

Copyright (c) 2017 Abedalkareem

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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.