Swift friendly localization and i18n with in-app language switching

Overview

Platform Version Build Status Carthage compatible

Localize-Swift

Localize-Swift is a simple framework that improves i18n and localization in Swift iOS apps - providing cleaner syntax and in-app language switching.

Features

  • Keep the Localizable.strings file your app already uses.
  • Allow your users to change the app's language without changing their device language.
  • Use .localized() instead of NSLocalizedString(key,comment) - a more Swifty syntax.
  • Generate your strings with a new genstrings swift/python script that recognises .localized().

Usage

Import Localize at the top of each Swift file that will contain localized text.

If CocoaPods -

import Localize_Swift

Add .localized() following any String object you want translated:

textLabel.text = "Hello World".localized()

To get an array of available localizations:

Localize.availableLanguages()

To change the current language:

Localize.setCurrentLanguage("fr")

To update the UI in the view controller where a language change can take place, observe LCLLanguageChangeNotification:

NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)

To reset back to the default app language:

Localize.resetCurrentLanguageToDefault()

genstrings

To support this new i18n syntax, Localize-Swift includes custom genstrings swift script.

Copy the genstrings.swift file into your project's root folder and run with

./genstrings.swift

This will print the collected strings in the terminal. Select and copy to your default Localizable.strings.

The script includes the ability to specify excluded directories and files (by editing the script).

[Preferrred] Setting up with Swift Package Manager

The Swift Package Manager is now the preferred tool for distributing Localize-Swift.

From Xcode 11+ :

  1. Select File > Swift Packages > Add Package Dependency. Enter https://github.com/marmelroy/Localize-Swift.git in the "Choose Package Repository" dialog.
  2. In the next page, specify the version resolving rule as "Up to Next Major" with "3.2.0".
  3. After Xcode checked out the source and resolving the version, you can choose the "Localize-Swift" library and add it to your app target.

For more info, read Adding Package Dependencies to Your App from Apple.

Alternatively, you can also add Localize-Swift to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/marmelroy/Localize-Swift.git", .upToNextMajor(from: "3.2.0"))
]

Setting up with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Localize-Swift into your Xcode project using Carthage, specify it in your Cartfile:

github "marmelroy/Localize-Swift"

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'Localize-Swift', '~> 3.2'
Comments
  • .localized() always returns English version

    .localized() always returns English version

    Hello,

    No matter what I am doing, after settings the language to any different language than "en", I always get translations from Localizable.strings of my en.lproj.

    I am using: Localize.setCurrentLanguage("fr-FR")

    and then after LCLLanguageChangeNotification notification, I call: backButton.setTitle("Back".localized(), forState: .Normal)

    The result is always the string "BACK".

    Am I doing something wrong?

    Thanks!

    opened by tolik85 7
  • New release for Swift 5 support?

    New release for Swift 5 support?

    I see Swift 5 support was added in https://github.com/marmelroy/Localize-Swift/commit/0af1491dc1f8f029fb3ca88a67a89b2324ca0019. Would it be possible to cut a new release?

    opened by getaaron 4
  • How to check the device current language using Localize-Swift?

    How to check the device current language using Localize-Swift?

    Is there a way to find out the device current language? I mean the language which is set in Settings by the user. So when our app would get installed before setting any language changes, if we can check for the device language?

    opened by hemangshah 4
  • Typo: Localize.resetCurrentLanguageToDefault()

    Typo: Localize.resetCurrentLanguageToDefault()

    please change the typo mistake:

    @IBAction func doResetLanguage(sender: AnyObject) { Localize.resetCurrentLanguageToDefault() >>>>> to >>> resetCurrentLanaguageToDefault() }

    opened by rosevinod 4
  • Spellings

    Spellings

    My apologies for a really nit picky PR that doesn't really add value, this it really just an opportunity for me to say thank you for creating a really helpful utility and I hope to jump on it properly in the near future. :-)

    opened by jameshartt 4
  • I wonder why my app not changing language

    I wonder why my app not changing language

    I am using CocoaPods to install this library. And then i started to add language that i want to translate for my app screen shot 2561-12-04 at 7 15 53 pm

    And then i created string file in order to translate language screen shot 2561-12-04 at 7 18 21 pm

    And this is my main viewController screen shot 2561-12-04 at 7 20 11 pm

    When i run the app and still show me Hello world text.

    Thank for help me out.

    opened by SamboVisal 3
  • Localize with Xcode 9

    Localize with Xcode 9

    I am try to localise in Arabic and unable to do that. setup my project as per example project, after language selection notification is calling but UI remained same. please let me know where i am doing wrong or missing something. i attached my project. SecondArabic.zip

    opened by Nauman7222 3
  • Support ignored directories with genstrings.py

    Support ignored directories with genstrings.py

    Running genstrings.py currently searches all directories, including Examples in the Carthage Checkouts folder. For instance, I get this output:

    /*
     * ./Carthage/Checkouts/Localize-Swift/examples/LanguageSwitch/Sample/ViewController.swift
     */
    
    "Hello world" = "Hello world";
    
    "Change" = "Change";
    
    "Reset" = "Reset";
    

    It would be helpful to have an --ignore option to ignore certain directories.

    opened by nuudles 3
  • Adding localized with format function

    Adding localized with format function

    I have been using your library really useful. However, why did you remove the localizedWithFormat feature? It is really useful in practical app development.

    opened by rokoroku 3
  • Suggestion: Change the Localized() method name to localized() to match style best practices

    Suggestion: Change the Localized() method name to localized() to match style best practices

    The library looks great! I believe that the Localized() method should be renamed to localized() though as Swift conventions dictate that method names start with a lowercase letter. For instance, check out this style guide: https://github.com/raywenderlich/swift-style-guide

    Use descriptive names with camel case for classes, methods, variables, etc. Class names should be capitalized, while method names and variables should start with a lower case letter.

    opened by nuudles 3
  • Change language in other ViewControllers

    Change language in other ViewControllers

    Hi @marmelroy! Thanks for this awesome library. I'm able to change the language on my Language ViewController and see the change. When I open my other ViewControllers the language hasn't changed on my set strings. When I quit the app and reopen they have changed though. How can I have other ViewControllers changed as well?

    opened by Tindi 2
  • English

    English "en" not listed in available language in iOS 16

    After updating to Xcode 14 and iOS 16. Getting a list of available languages in that language key en was not available. Could you please help me with this? thanks in advance @marmelroy @fassko

    opened by Elamuruga 0
  • Double % symbol is not escaped

    Double % symbol is not escaped

    We use mixed localizations for Android and iOs devices. For android devices, we have to escape the % symbol with another % symbol, which causes that in localizing definition we have a double %%. On iOS, we have a problem because Localize-Swift does not work with the % symbol as escaping. Is there any way how to solve it? Or do I need to write some custom overriding method to solve this?

    Localized text: "You have a 100%% discount"

    Current situation: "You have a 100%% discount"

    Expected: "You have a 100% discount"

    opened by wohral 1
  • Issue with: Pod - New build system - where different project targets have different deployment versions

    Issue with: Pod - New build system - where different project targets have different deployment versions

    We have different project targets that have different deployment versions.

    When running pod install, different pod targets are created with different names in this format: Localize-Swift-iOS<version>. When archiving using the new build system, the compiler complains that multiple commands produce localize-swift.framework.

    Full error description:

    Multiple commands produce '/Users/me/Library/Developer/Xcode/DerivedData/<productName>-gqrwpkrplsfsnnfqokkumktsqfzn/Build/Intermediates.noindex/ArchiveIntermediates/<productName>-Production/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Localize_Swift.framework':
    1) Target 'Localize-Swift-iOS12.1' has create directory command with output '/Users/me/Library/Developer/Xcode/DerivedData/<productName>-gqrwpkrplsfsnnfqokkumktsqfzn/Build/Intermediates.noindex/ArchiveIntermediates/<productName>-Production/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Localize_Swift.framework'
    2) Target 'Localize-Swift-iOS14.0' has create directory command with output '/Users/me/Library/Developer/Xcode/DerivedData/<productName>-gqrwpkrplsfsnnfqokkumktsqfzn/Build/Intermediates.noindex/ArchiveIntermediates/<productName>-Production/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Localize_Swift.framework'
    
    opened by Revanth-Kausikan 0
  • Update for Xcode 13

    Update for Xcode 13

    • Updated to Xcode 13

    • Fixed infinite loading when opening Main storyboard - eventually doesn't respond.

    • Added dark mode support and used Xcode 13 tinted buttons.

    • Fixed storyboard warning

    • Updated pod target

    opened by RevanthKausikan 0
  • Supporting object localize string ?

    Supporting object localize string ?

    how to organize localize string in an object ?

    "hello" = { "world" = "Hello World"; "indonesia" = "Hello Indonesia"; };

    "hello.indonesia".localized()

    opened by arifrach31 0
Releases(3.1.0)
Owner
Roy Marmelstein
Ya tu sabes.
Roy Marmelstein
Will Powell 1.2k Dec 29, 2022
Localization of the application with ability to change language "on the fly" and support for plural form in any language.

L10n-swift is a simple framework that improves localization in swift app, providing cleaner syntax and in-app language switching. Overview ?? Features

Adrian Bobrowski 287 Dec 24, 2022
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.

Localize Localize is a framework written in swift to help you localize and pluralize your projects. It supports both storyboards and strings. Features

Andres Silva 279 Dec 24, 2022
Localizations is an OS X app that manages your Xcode project localization files (.strings)

Localizations 0.2 Localizations is an OS X app that manages your Xcode project localization files (.strings). It focuses on keeping .strings files in

Arnaud Thiercelin 129 Jul 19, 2022
transai is a localization tool on Android and iOS.

transai transai is a command line tool to help you do Android and iOS translation management. You can extract string files to csv format, or generate

Jintin 56 Nov 12, 2022
iOS localization swift code generation project

code-gen-library - localization-swift module code-gen-library - localization-swift module with Python bash script execute to localization swift files(

umut boz 0 Oct 26, 2021
A CLI tool for localization resource management on Xcode. Built with Google Translator.

Supported by Jetbrains Open Source License Program Automatically translate and synchronize '.strings' files from the defined base language The basic c

gitmerge 164 May 4, 2022
Demo project of Swift language crash using Release build on iOS 14

Demo project of Swift language crash using Release build on iOS 14 Repro steps O

Daohan Chong 0 Mar 24, 2022
a custom language construction kit

Swifties a custom language construction kit intro Swifties aims to provide a flexible toolkit for creating custom languages in Swift. demo A custom Li

Andreas Nilsson 11 Aug 25, 2021
iOS implementation of the Catrobat language

Catty Catty, also known as Pocket Code for iOS, is an on-device visual programming system for iPhones. Catrobat is a visual programming language and s

null 74 Dec 25, 2022
Simple solution to localize your iOS App.

Hodor is a simple solution to localize your iOS App quickly, allow you to change language of project in-app without quiting the app, Just like WeChat.

Aufree 545 Dec 24, 2022
NoOptionalInterpolation gets rid of "Optional(...)" and "nil" in Swift's string interpolation

NoOptionalInterpolation gets rid of "Optional(...)" and "nil" in Swift's string interpolation

Thanh Pham 48 Jun 5, 2022
A tool for finding missing and unused NSLocalizedStrings

nslocalizer This is a command line tool that is used for discovering missing and unused localization strings in Xcode projects. Contributing and Code

Samantha Demi 155 Sep 17, 2022
Semi-automated Text Translator for Websites and Apps

macOS/Ubuntu/Windows: attranslate is a semi-automated tool for "synchronizing" translation-files. attranslate is optimized for fast and smooth rollout

Felix Kirchengast 272 Dec 21, 2022
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Jan 3, 2023
Localize iOS apps in a smarter way using JSON files. Swift framework.

Swifternalization Swift library that helps in localizing apps in a different, better, simpler, more powerful way than system localization does. It use

Tomasz Szulc 575 Nov 3, 2022
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.

Installation • Configuration • Usage • Build Script • Donation • Migration Guides • Issues • Contributing • License BartyCrouch BartyCrouch incrementa

Flinesoft 1.3k Jan 1, 2023
Will Powell 1.2k Dec 29, 2022
Localization of the application with ability to change language "on the fly" and support for plural form in any language.

L10n-swift is a simple framework that improves localization in swift app, providing cleaner syntax and in-app language switching. Overview ?? Features

Adrian Bobrowski 287 Dec 24, 2022
A Flutter tourism app that is backed-by Redux, shows animations, internationalization (i18n, English <=> Arabic), ClipPath, and fonts

A Flutter tourism app that is backed-by Redux, shows animations, internationalization (i18n, English <=> Arabic), ClipPath, and fonts. YouTube demo I

Abdulmomen Kadum عبدالمؤمن كاظم 277 Dec 28, 2022