{"id":16756054,"url":"https://github.com/mihaelisaev/localizer","last_synced_at":"2025-04-10T16:50:40.039Z","repository":{"id":56919947,"uuid":"201653519","full_name":"MihaelIsaev/Localizer","owner":"MihaelIsaev","description":"🇮🇸🇩🇪🇯🇵🇲🇽 Swift localization helper","archived":false,"fork":false,"pushed_at":"2020-06-07T20:52:17.000Z","size":39,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-23T10:32:12.905Z","etag":null,"topics":[],"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/MihaelIsaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-10T16:12:30.000Z","updated_at":"2024-03-10T06:20:14.000Z","dependencies_parsed_at":"2022-08-21T04:50:32.596Z","dependency_job_id":null,"html_url":"https://github.com/MihaelIsaev/Localizer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FLocalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FLocalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FLocalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FLocalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MihaelIsaev","download_url":"https://codeload.github.com/MihaelIsaev/Localizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248255763,"owners_count":21073378,"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":[],"created_at":"2024-10-13T03:24:42.048Z","updated_at":"2025-04-10T16:50:40.013Z","avatar_url":"https://github.com/MihaelIsaev.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg\" alt=\"MIT License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/swift-4.2-brightgreen.svg\" alt=\"Swift 4.2\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://cocoapods.org/pods/Localizer-Plus\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/v/Localizer.svg\" alt=\"Cocoapod\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://discord.gg/q5wCPYv\"\u003e\n        \u003cimg src=\"https://img.shields.io/discord/612561840765141005\" alt=\"Swift.Stream\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n# Localizer\n\nInstall through Swift Package Manager\n\n```swift\n.package(url: \"https://github.com/MihaelIsaev/Localizer.git\", from: \"1.0.2\")\n```\n\nor CocoaPods\n\n```\npod 'Localizer', '~\u003e 1.0.2'\n```\n\n# How to use\n\nThe most important part is to import it 🚀\n```swift\nimport Localizer\n```\n\n### iOS\n\n```swift\n// create string relative to current language\nlet myString = String(\n    .en(\"Hello\"),\n    .fr(\"Bonjour\"),\n    .ru(\"Привет\"),\n    .es(\"Hola\"),\n    .zh_Hans(\"你好\"),\n    .ja(\"こんにちは\"))\nprint(myString)\n```\n\nBy default current language is equal to `Locale.current` but you can change it by setting `Localizer.current = .en`.\nAlso localizer have `default` language in case if user's language doesn't match any in your string, and you could set it just by calling `Localizer.default = .en`.\n\n### Server-side\n\nOn server-side we can't detect user's locale through `Locale.current` cause this way we will get server's locale :)\n\nSo e.g. if we have `User` model on server which is have `locale` string variable we could use it. For that we should conform `User` to `Localizable` like this\n\n```swift\nclass User: Localizable {\n    // declare this as a link to locale variable in this model\n    static var localeKey: LocaleKey? { return \\.locale }\n\n    var id: UUID\n    var email, password: String\n\n    /// this variable will be used for Localizer to detect language\n    /// it should contain e.g. short `en` or long `en_US` value\n    var locale: String?\n}\n```\nthen declare your localized strings with `user` obejct like this\n```swift\nlet myString = String(for: user,\n    .en(\"Hello\"),\n    .fr(\"Bonjour\"),\n    .ru(\"Привет\"),\n    .es(\"Hola\"),\n    .zh_Hans(\"你好\"),\n    .ja(\"こんにちは\"))\nprint(myString)\n```\n\nEasy, right? :) Would be great if you could give it a star ⭐️\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmihaelisaev%2Flocalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmihaelisaev%2Flocalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmihaelisaev%2Flocalizer/lists"}