{"id":15038082,"url":"https://github.com/andresilvagomez/localize","last_synced_at":"2025-04-05T18:08:57.753Z","repository":{"id":47065840,"uuid":"78894467","full_name":"andresilvagomez/Localize","owner":"andresilvagomez","description":"Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.","archived":false,"fork":false,"pushed_at":"2021-09-17T08:12:38.000Z","size":782,"stargazers_count":293,"open_issues_count":11,"forks_count":49,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-05T18:08:53.826Z","etag":null,"topics":["apple-strings","carthage","cocoapods","json","language","localization","localized","storyboard","storyboards","swift","swift4","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andresilvagomez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-13T23:20:34.000Z","updated_at":"2024-11-19T08:15:06.000Z","dependencies_parsed_at":"2022-09-04T19:10:50.106Z","dependency_job_id":null,"html_url":"https://github.com/andresilvagomez/Localize","commit_stats":null,"previous_names":["kekiiwaa/jsonlocalizable"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilvagomez%2FLocalize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilvagomez%2FLocalize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilvagomez%2FLocalize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilvagomez%2FLocalize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andresilvagomez","download_url":"https://codeload.github.com/andresilvagomez/Localize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378149,"owners_count":20929297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple-strings","carthage","cocoapods","json","language","localization","localized","storyboard","storyboards","swift","swift4","xcode"],"created_at":"2024-09-24T20:37:01.508Z","updated_at":"2025-04-05T18:08:57.736Z","avatar_url":"https://github.com/andresilvagomez.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Localize\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![codecov.io](https://codecov.io/github/andresilvagomez/Localize/coverage.svg?branch=master)](https://codecov.io/github/andresilvagomez/Localize?branch=master)\n[![CocoaPods](https://img.shields.io/cocoapods/v/Localize.svg)](https://cocoapods.org/pods/Localize)\n[![Build Status](https://travis-ci.org/andresilvagomez/Localize.svg?branch=master)](https://travis-ci.org/andresilvagomez/Localize)\n[![Language](https://img.shields.io/badge/language-Swift%204.1-orange.svg)](https://swift.org)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/andresilvagomez/Localize/master/LICENSE)\n[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/vsouza/awesome-ios)\n\nLocalize is a framework written in swift to help you localize and pluralize your projects. It supports both storyboards and strings.\n\n![Localize Storyboard](https://www.dropbox.com/s/t5uij0bg0tgignu/localize.gif?raw=1)\n___\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Notes for your App Store release](#notes-for-your-appstore-release)\n- [Credits](#credits)\n- [License](#license)\n\n## Features\n\n- [x] Storyboard with IBInspectable\n- [x] Pluralize and localize your keys\n- [x] Keep the File.strings files your app already uses\n- [x] Support Apple strings and JSON Files\n- [x] Change your app language without changing device language\n- [x] Localize your Storyboards without extra files or/and ids\n\n## Requirements\n\n- iOS 9.0+\n- Xcode 8.0+\n- Swift 3.0+\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\ngem install cocoapods\n```\n\n\u003e CocoaPods 1.1.0+ is required to build Localize 1.+.\n\nTo integrate Localize into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '9.0'\nuse_frameworks!\n\ntarget '\u003cYour Target Name\u003e' do\n    pod 'Localize' , '~\u003e 2.3.0'\nend\n\n# If you are using Swift 4.x\n# target '\u003cYour Target Name\u003e' do\n#    pod 'Localize' , '~\u003e 2.1.0'\n# end\n```\n\nThen, run the following command:\n\n```bash\npod install\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\nbrew update\nbrew install carthage\n```\n\nTo integrate Localize into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```carthage\ngithub \"andresilvagomez/Localize\"\n```\n\nRun `carthage update` to build the framework and drag the built `Localize.framework` into your Xcode project.\n\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the swift compiler.\n\nOnce you have your Swift package set up, adding Localize as a dependency is as easy as adding it to the dependencies value of your Package.swift.\n\n```swift\ndependencies: [\n    .Package(url: \"https://github.com/andresilvagomez/Localize.git\")\n]\n```\n\n___\n\n## Usage\n\nAdd ```.localize()``` for any ```String``` if you want localize.\n\nYou don't need import anything in your code, Localize uses extensions to localize your Strings.\n\n```swift\n\ntextLabel.text = \"hello.world\".localize()\n// Or\ntextLabel.text = \"hello.world\".localized\n\n```\n\nYou can decide if you want use JSON or Apple Strings, we support both, if you decide to use JSON please follow these instructions.\n\n### Create JSON file\n\nPlease create a JSON file in your code with this rule:\n\n```strings\n{your file name}-{your lang code}.json\n```\n\nFor example\n\n- lang-en.json\n- lang-es.json\n- lang-fr.json\n\nExample JSON File\n\n```json\n{\n    \"hello\" : {\n        \"world\" : \"Hello world!\",\n        \"name\" : \"Hello %!\"\n    },\n    \"values\" : \"Hello % we are %, see you soon\",\n    \"username\" : \"My username is :username\",\n    \"navigation.title\" : \"\"\n}\n```\n\n### Create String file\n\nIf you decide use Apple strings, please follow [Apple Localization Guide](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html) to create strings file.\n\nString file example\n\n```strings\n\n\"hello.world\" = \"Hello world!\";\n\n\"name\" = \"Hello %\";\n\n\"values\" = \"Hello everyone my name is % and I'm %, see you soon\";\n\n\"username\" = \"My username is :username\";\n\n\"level.one.two.three\" = \"This is a multilevel key\";\n\n\"the.same.lavel\" = \"This is a localized in the same level\";\n\n\"enlish\" = \"This key only exist in english file.\";\n\n```\n\nWhatever way you choose to, use that methods.\n\n### Localize strings\n\n```swift\n\nprint( \"hello.world\".localize() )\n\n// Hello world!\n\n// Also you can use\n\nprint( \"hello.world\".localized )\n\n```\n\n### Localize strings, replacing text\n\nLocalize use `%` identifier to replace the text\n\n```swift\n\nprint( \"hello.name\".localize(value: \"everyone\") )\n\n// Hello everyone!\n\n```\n\n### Localize strings, replacing many texts\n\nLocalize use `%` identifier to replace the text\n\n```swift\n\nprint( \"values\".localize(values: \"everyone\", \"Software Developer\") )\n\n// Hello everyone we are Software Developer, see you soon\n\n```\n\n### Localize strings, replacing dictionary values\n\nLocalize use `:yourid` to search your id in JSON File\n\n```swift\n\nprint( \"username\".localize(dictionary: [\"username\": \"Localize\"]) )\n\n// My username is Localize\n\n```\n\n### Localize strings, using other files\n\nIf you decide use different files use methods with ```tableName``` in the end of each method, for example.\n\n```swift\n\nprint( \"hello.world\".localize(tableName: \"Other\") )\n\nprint( \"hello.name\".localize(value: \"everyone\", tableName: \"Errors\") )\n\nprint( \"values\".localize(values: \"everyone\", \"Software Developer\", tableName: \"YourFileName\") )\n\nprint( \"username\".localize(dictionary: [\"username\": \"Localize\"], tableName: \"YourFileName\") )\n\n```\n\n___\n\n### We are amazing with storyboards\n\nYou don't need to import anything in your code, Localize uses extensions to localize your UIView components\n\nTo prevent auto localization for some controls you created in storyboard can set **Auto Localize** to **Off**\n\n![Localize Storyboard](https://image.ibb.co/m5yz6V/screenshot.png)\n\n- lang-en.json\n\n```json\n{\n    \"navigation\" : {\n        \"title\" : \"Localize\"\n    },\n    \"app\" : {\n        \"label\" : \"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.\",\n        \"textfield\" : \"Write some here.\"\n    }\n}\n```\n\nYou can use extensions for\n\n- `UIBarButtonItem`\n- `UIButton`\n- `UILabel`\n- `UINavigationItem`\n- `UISearchBar`\n- `UISegmentedControl`\n- `UITabBarItem`\n- `UITextField`\n- `UITextView`\n\n___\n\n## Updating language\n\nWhen you change a language, automatically all views update your content to new language\n\n```swift\n\nLocalize.update(language: \"fr\")\n\n```\n\nTo make this work with strings, you need to implement a notification\n\n```swift\n\noverride func viewDidLoad() {\n    super.viewDidLoad()\n    NotificationCenter.default.addObserver(self, selector: #selector(localize), name: NSNotification.Name(localizeChangeNotification), object: nil)\n}\n\npublic func localize() {\n    yourLabel.text = \"app.names\".localize(values: \"mark\", \"henrry\", \"peater\")\n    otherLabel.text = \"app.username\".localize(value: \"Your username\")\n}\n\n```\n\nImplementing internal acction to change a language\n\n```swift\n\n@IBAction func updateLanguage(_ sender: Any) {\n    let actionSheet = UIAlertController(title: nil, message: \"app.update.language\".localize(), preferredStyle: UIAlertControllerStyle.actionSheet)\n    for language in Localize.availableLanguages {\n        let displayName = Localize.displayNameForLanguage(language)\n        let languageAction = UIAlertAction(title: displayName, style: .default, handler: {\n            (alert: UIAlertAction!) -\u003e Void in\n            Localize.update(language: language)\n            })\n        actionSheet.addAction(languageAction)\n    }\n    let cancelAction = UIAlertAction(title: \"Cancel\", style: UIAlertActionStyle.cancel, handler: {\n        (alert: UIAlertAction) -\u003e Void in\n        })\n    actionSheet.addAction(cancelAction)\n    self.present(actionSheet, animated: true, completion: nil)\n}\n\n```\n\n### Config\n\nThis not is necesary, only if you need different results.\n\n```swift\n// AppDelegate.swift\n\nimport Localize\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n\n    let localize = Localize.shared\n    // Set your localize provider.\n    localize.update(provider: .json)\n    // Set your file name\n    localize.update(fileName: \"lang\")\n    // Set your default language.\n    localize.update(defaultLanguage: \"fr\")\n    // If you want change a user language, different to default in phone use thimethod.\n    localize.update(language: \"en\")\n    // If you want remove storaged language use\n    localize.resetLanguage()\n    // The used language\n    print(localize.currentLanguage)\n    // List of available language\n    print(localize.availableLanguages)\n\n    // Or you can use static methods for all\n    Localize.update(fileName: \"lang\")\n    Localize.update(defaultLanguage: \"fr\")\n    Localize.update(language: \"en-DE\")\n\n    return true\n}\n\n```\n\n## Pluralize\n\n```swift\nprint( \"people\".pluralize(value: 0) )\n// there are no people\n\nprint( \"people\".pluralize(value: 1) )\n// only one person\n\nprint( \"people\".pluralize(value: 2) )\n// two people\n\nprint( \"people\".pluralize(value: 27) )\n// many people\n\nprint( \"people\".pluralize(value: 103) )\n// hundreds of people\n\nprint( \"people\".pluralize(value: 1010) )\n// thousand of people\n\nprint( \"people\".pluralize(value: 1000000) )\n// millions of people\n```\n\nhow you need compose your file.\n\n```json\n// Json file\n\n{\n    \"people\": {\n        \"zero\": \"there are no people\",\n        \"one\": \"only one person\",\n        \"two\": \"two people\",\n        \"many\": \"many people\",\n        \"hundreds\": \"hundreds of people\",\n        \"thousand\": \"thousand of people\",\n        \"millions\": \"millions of people\",\n        \"other\": \"not defined people\"\n    }\n}\n```\n\n```strings\n# string file\n\n\"people.zero\" = \"there are no people\";\n\"people.one\" = \"only one person\";\n\"people.two\" = \"two people\";\n\"people.many\" = \"many people\";\n\"people.hundreds\" = \"hundreds of people\";\n\"people.thousand\" = \"thousand of people\";\n\"people.millions\" = \"millions of people\";\n\"people.other\" = \"not defined people\";\n```\n\nbut also you can show your value\n\n```swift\nprint( \"people\".pluralize(value: 1) )\n/// 1 Person\n```\n\nin your file\n\n```json\n// JSON\n{\n    \"people\": {\n        \"one\": \"% Person\",\n        ...\n    }\n}\n\n// Strings\n\"people.one\" = \"% Person\";\n```\n\n___\n\n## Notes for your AppStore release\n\nTo make all languages you have localized your app for visible on the AppStore, you must add a language in the project's settings.\n\n1. For that, click on your project name in the left side bar.\n2. Then, choose project, instead of a target.\n3. At the bottom, under *Localizations*, press the + button \u0026 select a language you want to add\n4. On prompt, uncheck all files Xcode wants to add localization for, but keep a single one, that you won't actually localize, such as your launch screen for instance.\n    - if you need to localize all your files, I suggest adding a placeholder storyboard file that you'll then add to localization\n5. Done! (You don't actually have to localize the placehodler file.) The AppStore will now show the new language in localizations for your app.\n\n___\n\n## Credits\n\n[Andres Silva Gomez](https://github.com/andresilvagomez)\n\nSpecial thanks to [Benjamin Erhart](https://github.com/tladesignz)\n\n## License\n\nLocalize is released under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresilvagomez%2Flocalize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandresilvagomez%2Flocalize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresilvagomez%2Flocalize/lists"}