{"id":20227726,"url":"https://github.com/andreabbondanza/dewxamarinlocalization","last_synced_at":"2025-10-10T07:34:19.513Z","repository":{"id":96834448,"uuid":"118258967","full_name":"andreabbondanza/DewXamarinLocalization","owner":"andreabbondanza","description":"A .NET standard helper for xamarin localization in shared projects","archived":false,"fork":false,"pushed_at":"2018-04-05T12:50:49.000Z","size":20,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T20:48:59.860Z","etag":null,"topics":["dotnet-core","dotnetcore","dotnetstandard","xamarin","xamarin-forms"],"latest_commit_sha":null,"homepage":null,"language":"C#","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/andreabbondanza.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-20T16:15:17.000Z","updated_at":"2020-10-12T22:20:20.000Z","dependencies_parsed_at":"2023-04-08T20:56:13.455Z","dependency_job_id":null,"html_url":"https://github.com/andreabbondanza/DewXamarinLocalization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andreabbondanza/DewXamarinLocalization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2FDewXamarinLocalization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2FDewXamarinLocalization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2FDewXamarinLocalization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2FDewXamarinLocalization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreabbondanza","download_url":"https://codeload.github.com/andreabbondanza/DewXamarinLocalization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2FDewXamarinLocalization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003192,"owners_count":26083533,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dotnet-core","dotnetcore","dotnetstandard","xamarin","xamarin-forms"],"created_at":"2024-11-14T07:26:16.233Z","updated_at":"2025-10-10T07:34:19.484Z","avatar_url":"https://github.com/andreabbondanza.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DewXamarinLocalization\nA .NET standard helper for xamarin forms localization in shared projects\n\n\n\n\n\n\n\n# How to use\nMy first though was about that this localization system must be easy, and (maybe it can be still better, who knows?) I think I've done it!\n\n## Install package\nYour first step is to install the DewXamarinLocalization in your projects (all, you can use solution nuget package manager)\n\n## Files\nThe files are simple json dictionary, like this:\n```json\n{\n  \"AppTitle\": \"DewLocalization!\",\n  \"AboutTitle\": \"Dew is great!\"\n}\n```\n# IMPORTANT! --------------------------\nThese steps are important!\n#### Tree example\n```text\n-Shared project\n |\n |-Localized\n     |- it-it.json\n     |- en-us.json\n |- Views\n |- etc.\n```\n\n__Every file content must be at least \"{}\".__\n#### Naming\nThis is really important, you must be carefull about the file names.\nEvery filename __MUST__ correspond to the __CultureInfo__ [Name property](https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.name?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(System.Globalization.CultureInfo.Name);k(DevLang-csharp)%26rd%3Dtrue\u0026view=netframework-4.7.1) in lower case (en-us,it-it,it-ch,en-gb,fr-fr,etc.) and must be __json__. Obviously if your app support 3 languages, you should have 3 different culture and you must support all of them.\n#### Path\nThe file __MUST__ be placed in a folder called __Localized__ in the shared project. \n#### Embedded\nWhen you create the file, you __MUST__ set in the properties _\"Embedded resource\"_ like _Build Action_\n## NOTE\nIf a file for a culture isn't present you'll get an exception when the app is opening __only__ with that culture.\n# IMPORTANT! --------------------------\n## XAML Code\n\nThis page is from the xamarin.forms base template for a new app.\n\n```xaml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cTabbedPage xmlns=\"http://xamarin.com/schemas/2014/forms\"\n            xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\"\n            xmlns:views=\"clr-namespace:ExampleApp.Views\"\n            xmlns:loc=\"clr-namespace:DewCore.Xamarin.Localization;assembly=DewXamarinLocalization\"\n            x:Class=\"ExampleApp.Views.MainPage\"\u003e\n    \u003cTabbedPage.Children\u003e\n        \u003cNavigationPage Title=\"{loc:_ S=AppTitle}\"\u003e\n            \n            \u003cNavigationPage.Icon\u003e\n                \u003cOnPlatform x:TypeArguments=\"FileImageSource\"\u003e\n                    \u003cOn Platform=\"iOS\" Value=\"tab_feed.png\"/\u003e\n                \u003c/OnPlatform\u003e\n            \u003c/NavigationPage.Icon\u003e\n            \u003cx:Arguments\u003e\n                \u003cviews:ItemsPage /\u003e\n            \u003c/x:Arguments\u003e\n        \u003c/NavigationPage\u003e\n        \n        \u003cNavigationPage Title=\"{loc:_ S=AboutTitle}\"\u003e\n            \u003cNavigationPage.Icon\u003e\n                \u003cOnPlatform x:TypeArguments=\"FileImageSource\"\u003e\n                    \u003cOn Platform=\"iOS\" Value=\"tab_about.png\"/\u003e\n                \u003c/OnPlatform\u003e\n            \u003c/NavigationPage.Icon\u003e\n            \u003cx:Arguments\u003e\n                \u003cviews:AboutPage /\u003e\n            \u003c/x:Arguments\u003e\n        \u003c/NavigationPage\u003e\n    \u003c/TabbedPage.Children\u003e\n\u003c/TabbedPage\u003e\n```\n\nHow you can see, your first step is to import the namespace:\n```text\nxmlns:loc=\"clr-namespace:DewCore.Xamarin.Localization;assembly=DewXamarinLocalization\"\n```\nAfter this you can use it thanks the Markup extension\n\n```text\n\u003cNavigationPage Title=\"{loc:_ S=AppTitle}\"\u003e\n```\n\n#### Another approach\nYou can also set the strings in this way\n```xaml\n\u003cNavigationPage \u003e\n    \u003cNavigationPage.Title\u003e\n        \u003cloc:_ S=\"AppTitle\"/\u003e\n    \u003c/NavigationPage.Title\u003e\n    \u003cNavigationPage.Icon\u003e\n        \u003cOnPlatform x:TypeArguments=\"FileImageSource\"\u003e\n            \u003cOn Platform=\"iOS\" Value=\"tab_feed.png\"/\u003e\n        \u003c/OnPlatform\u003e\n    \u003c/NavigationPage.Icon\u003e\n    \u003cx:Arguments\u003e\n        \u003cviews:ItemsPage /\u003e\n    \u003c/x:Arguments\u003e\n\u003c/NavigationPage\u003e\n```\n#### In code\n\nIf you need to acces to the dictionary in code behind you can this way:\n```csharp\npublic void Test()\n{\n    System.Diagnostics.Debug.Write(_.GetString(\"AppTitle\"))\n}\n```\n\n## If string doesn't exists?\n\nThe localization system is based on aspnet core middleware [DewLocalizationMiddleaware](https://github.com/andreabbondanza/DewLocalizationMiddleware) and works in the same way.\n\nFiles must be present otherwise you'll get an exception, but strings doesn't need this.\n\nIf a string doesn't exists, the Localization class just return the key value.\n\nThis way if you want you can use the default word like key, so if in the translation it doesn't exists it will return the key self.\n\nAn example\n\n```xaml\n\u003cNavigationPage Title=\"{loc:_ S='My App\\'s name'}\"\u003e\n```\nor\n```xaml\n\u003cNavigationPage.Title\u003e\n    \u003cloc:_ S=\"My App's name\"/\u003e\n\u003c/NavigationPage.Title\u003e\n```\n\nIf the it-it.json file contains a voice for \"My App's name\", it will be translated, otherwise the app will print \"My App's name\" (that is the key).\n## Change dictionary in runtime\n\nIf you want change the dictionary in runtime, you shouuld just do:\n```csharp\npublic async Task Test()\n{\n    var newCulture = new System.Globalization.CultureInfo(\"it-IT\");\n    await _.ChangeCulture(newCulture);\n    System.Diagnostics.Debug.Write(_.GetString(\"AppTitle\"));\n    newCulture = new System.Globalization.CultureInfo(\"en-US\");\n    await _.ChangeCulture(newCulture);\n    System.Diagnostics.Debug.Write(_.GetString(\"AppTitle\"));\n}\n```\n\n### Scenario where you want change your language at app's start\n\nIf you want to change the language in app start, your first approach is to place the _ChangeCulture_ call into __OnStart__ event but it won't work.\nThis because the _ChangeCulture_ method is __asyncronous__, and the App will initialize via Xaml and this will create a conflict (with crashes sometimes).\n\nAnother approach is to change the culture in the __OnAppaering__ event of the main page, and it works, but only for the next pages, because the mainpage will be loaded with the currentculture language.\n\nIf you try to call ChangeCulture method into App constructor you'll get a NullReferenceException because DewXamarinLocalization class depends from Application class.\n\nA solution for this particular problem is done with the static property __CultureStringOverride__.\n\nThis property is mono-use (after set it, you should call _LoadDictionary_ method, that will read it and will delete it) didn't has dependencies, so you can call into __App__ constructor without problem.\n\nLike I've said, you __SHOULD__ call _LoadDictionary_ after set this property, but, in this particular case, will be XAML the creator of the DewXamarinLocalization class. \n\n__NOTE:__ If you set property and after call LoadDictionary you'll get the same result of a call of _ChangeCulture_, so you should use this property only for this scenario.\n\n#### Example:\n\n```csharp\npublic App ()\n{\n    InitializeComponent();\n    var cul = LoadMyCultureFromSettings(); // this must be the culture name, like \"it-it\",\"en-us\", etc. in lower case, see Naming paragraph for more.\n    DewCore.Xamarin.Localization._.CultureStringOverride = cul;\n    MainPage = new MainPage();\n}\n\n```\n\n## Default culture\n\nThere is now a __DefaultCulture__ property.\n\nYou can add a default culture to prevent crashes when a culture resource doesn't extist.\n\nFor example if you set as __Default Culture__ \"en-us\" and you try to load the culture \"it-it\", if the resource doesn't exists the system will try to load the \"en-us\" culture resource. \n\nIf also the en-us culture resource doesn't exists, the system will try to load the current culture's resource but, if also this will be missed, the system will launch an exception.\n\nYou should set the __DefaultCulture__ property into the app constructor.\n\n\n## Note \nAdded __DefaultCulture__ property (Must correspond to [Name Property](https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.name?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(System.Globalization.CultureInfo.Name);k(DevLang-csharp)%26rd%3Dtrue\u0026view=netframework-4.7.1) in lower case)\n## NuGet\nYou can find it on nuget with the name [DewXamarinLocalization](https://www.nuget.org/packages/DewXamarinLocalization/)\n\n## About\n[Andrea Vincenzo Abbondanza](http://www.andrewdev.eu)\n\n## Donate\n[Help me to grow up, if you want](https://payPal.me/andreabbondanza)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreabbondanza%2Fdewxamarinlocalization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreabbondanza%2Fdewxamarinlocalization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreabbondanza%2Fdewxamarinlocalization/lists"}