{"id":27307507,"url":"https://github.com/ukcoderj/i18nstronglytypedcore","last_synced_at":"2025-07-05T23:09:12.366Z","repository":{"id":98400900,"uuid":"149471323","full_name":"ukcoderj/i18nStronglyTypedCore","owner":"ukcoderj","description":"source code for nuget package i18nStronglyTypedCore. It's a strongly typed i18n resource provider for .net core","archived":false,"fork":false,"pushed_at":"2018-10-01T15:04:50.000Z","size":1146,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T07:05:36.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ukcoderj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-09-19T15:21:45.000Z","updated_at":"2018-10-01T15:04:52.000Z","dependencies_parsed_at":"2023-06-26T00:18:55.903Z","dependency_job_id":null,"html_url":"https://github.com/ukcoderj/i18nStronglyTypedCore","commit_stats":null,"previous_names":["ukcoderj/i18nstronglytypedcore"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ukcoderj/i18nStronglyTypedCore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ukcoderj%2Fi18nStronglyTypedCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ukcoderj%2Fi18nStronglyTypedCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ukcoderj%2Fi18nStronglyTypedCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ukcoderj%2Fi18nStronglyTypedCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ukcoderj","download_url":"https://codeload.github.com/ukcoderj/i18nStronglyTypedCore/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ukcoderj%2Fi18nStronglyTypedCore/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263819236,"owners_count":23516122,"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":"2025-04-12T04:10:17.098Z","updated_at":"2025-07-05T23:09:12.345Z","avatar_url":"https://github.com/ukcoderj.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i18nStronglyTypedCore\n\nThis is the source code for [the i18nStronglyTypedCore nuget package](https://www.nuget.org/packages/i18nStronglyTypedCore).\n\n[Github source code](https://github.com/HockeyJustin/i18nStronglyTypedCore)\n\n## About\n\nThis is a .net core port of [afana's](http://afana.me/archive/2013/11/01/aspnet-mvc-internationalization-store-strings-in-database-or-xml.aspx/) excellent i18n (internationalization) provider for MVC 5, using xml for the resource strings. \n\nThere's also some extras, such as per request language responses and multiple resource file handling (see tutorial below).\n \nOf course, dotnet core has its' own [i18n provider](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1) \nbut like many people, I'd rather keep things strongly typed as much as possible. It's simple to get up and running.\n\nThe upsides to this package are:\n1. Strongly typed\n2. Seems pretty solid\n3. Only takes a couple of minutes to get up and running.\n4. Can handle multiple resource files.\n5. Can handle \"per request\" language responses (see tutorial)\n\nThe downsides to this package are:\n1. *Doesn't work with Attributes (the standard .net core one does)\n2. If you create the c# part, but forget to put anything in the xml, the error is a bit tricky to work out.\n\n## Prerequisites\n\n- Dotnet core 2.1+\n\n## To get up and running (quick tutorial)\n\n1. Create an asp.net core application. \n- In Visual Studio this is:\n- File \u003e New \u003e Project \u003e Web Tab \u003e Asp.NET Core Web Application\n\n- Give it a name (and location, not the one used in the pic) and hit ok\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/1.png?raw=true)\n\nc. Choose the mvc option (which this tutorial uses) and hit ok.\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/2.png?raw=true)\n\n\n2. Via the CLR or Package Manager (View \u003e Other Windows \u003e Package Manager Console) enter the following, then hit enter:\n\n`Install-Package i18nStronglyTypedCore`\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/3.png?raw=true)\n\n3. In wwwroot, add a folder called Resources and in that add an xml file called Resources.xml\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/4.png?raw=true)\n\n4. In resources.xml, insert the following placeholder content:\n\n\u003e *WARNING*: The following example has the default culture to be British English (en-GB). You may need `en-US` or [another culture](https://msdn.microsoft.com/en-us/library/hh441729.aspx).\n\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cresources\u003e\n    \u003c!-- ENGLISH --\u003e\n    \u003cresource culture=\"en-GB\" type=\"string\" name=\"Site_Name\" value=\"Site name (english)\"\u003e\u003c/resource\u003e\n    \n    \u003c!-- FRENCH --\u003e\n    \u003cresource culture=\"fr-FR\" type=\"string\" name=\"Site_Name\" value=\"Site name (Francais)\"\u003e\u003c/resource\u003e\n\n\u003c/resources\u003e\n```\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/4a.png?raw=true)\n\n5. Add a top level folder called 'Resources' (not in wwwroot) and create a class called `i18n`.\n\n6. Have that class inherit from `i18nStronglyTypedCore.i18n` and include the following property in the class.\n\n`public static string Site_Name { get { return GetStringValue(); } }`\n\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/5.png?raw=true)\n\n7. In startup.cs 'Configure' method, add the following 2 lines to initialise the resources.\n\n```\nvar pathToResources = System.IO.Path.Combine(env.WebRootPath, @\"Resources\\Resources.xml\");\nResources.i18n.InitResources(pathToResources);\n```\n\n\u003e NOTE: If yo have more than one resource file, you can add multiple files as shown below (but don't copy for this tutorial, as we only have 1 resource file)  \n\n```\nvar pathToResourcesEn = System.IO.Path.Combine(env.WebRootPath, @\"Resources\\Resources.xml\");\nvar pathToResourcesFr = System.IO.Path.Combine(env.WebRootPath, @\"Resources\\Resources-fr.xml\");\nResources.i18n.InitResources(new string[] { pathToResourcesEn, pathToResourcesFr });\n```\n\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/6.png?raw=true)\n\n8. In views/home/index, remove the standard content and add the following (remember to replace 'Testweb' with you own website's namespace).\n\n```\n@{\n    ViewData[\"Title\"] = \"Home Page\";\n}\n\u003ch4\u003eEnglish Site Name\u003c/h4\u003e\n\u003cp\u003e@Testweb.Resources.i18n.Site_Name\u003c/p\u003e\n\n\u003ch4\u003eFrench Site Name\u003c/h4\u003e\n\u003cp\u003e@Testweb.Resources.i18n.GetLocalisedStringValue(() =\u003e Testweb.Resources.i18n.Site_Name, \"fr-FR\")\u003c/p\u003e\n```\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/7.png?raw=true)\n\n9. Run the website. The end result should look like this.\n\nNOTE: The provider will take from the current culture by default.\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/8.png?raw=true)\n\n10. There are many ways to change the default culture. As a quick example, you could place the following in Startup.cs Configure method (before the resources code!)\n\n```\nvar cultureInfo = new System.Globalization.CultureInfo(\"fr-FR\");\nSystem.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;\nSystem.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;\n```\n\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/9.png?raw=true)\n\n\n11. Now run the site. The default culture will also be in french. Remove the work done in step 10 to get back to normal.\n\n![alt tag](https://github.com//HockeyJustin/i18nStronglyTypedCore/blob/master/i18nStronglyTypedMVC/i18nStronglyTypedMVC/wwwroot/images/10.png?raw=true)\n\n\n## To add more properties\n\n1. Copy the `Site_Name` property in Resources/i18n.cs i.e. \n\n`public static string Site_Name { get { return GetStringValue(); } }` \n\n2. Paste it on a new line and change the proterty name e.g. \n\n```\nnamespace Testweb.Resources\n{\n    public class i18n : i18nStronglyTypedCore.i18n\n    {\n        public static string Site_Name { get { return GetStringValue(); } }\n\n        public static string Hello_Text { get { return GetStringValue(); } }\n\n        // Add more here...\n    }\n}\n```\n\n3. Go to the resources.xml file. Copy the `Site_Name` resource and paste below. Change the `name` attribute (`Site_Name`) \nto match the name of your new property (e.g. `Hello_Text`) and update the value e.g.\n\n`\u003cresource culture=\"en-GB\" type=\"string\" name=\"Hello_Text\" value=\"Hello\"\u003e\u003c/resource\u003e`\n\n4. For other languages, copy + paste your new row, remembering to change the `culture` attribute and value. e.g. \n\n`\u003cresource culture=\"fr-FR\" type=\"string\" name=\"Hello_Text\" value=\"Bonjour\"\u003e\u003c/resource\u003e`\n\n5. So your final Resources.xml will look something like this:\n\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cresources\u003e\n    \u003c!-- ENGLISH (this could be en-US) --\u003e\n    \u003cresource culture=\"en-GB\" type=\"string\" name=\"Site_Name\" value=\"Site name (english)\"\u003e\u003c/resource\u003e\n    \u003cresource culture=\"en-GB\" type=\"string\" name=\"Hello_Text\" value=\"Hello\"\u003e\u003c/resource\u003e\n\n    \u003c!-- FRENCH --\u003e\n    \u003cresource culture=\"fr-FR\" type=\"string\" name=\"Site_Name\" value=\"Site name (Francais)\"\u003e\u003c/resource\u003e\n    \u003cresource culture=\"fr-FR\" type=\"string\" name=\"Hello_Text\" value=\"Bonjour\"\u003e\u003c/resource\u003e\n\n\u003c/resources\u003e\n\n```\n\n6. And you would call it like this (Razor) (remember your namespace might be different to `Testweb`):\n\n`@Testweb.Resources.i18n.Hello_Text`\n\n7. Or like this (C#)\n\n```\n// Your default culture\nvar hello = Resources.i18n.Hello_Text;\n// A request for the french resource\nvar bonjour = Resources.i18n.GetLocalisedStringValue(() =\u003e Testweb.Resources.i18n.Hello_Text, \"fr-FR\");\n```\n\nEND\n\n\n\u003e Remember, you can split your resource files if needed (see section 7 of 'To get up and running' above). This tutorial has only used one file for simplicity.\n\nAlso, if you want to get a list of all the cultures (e.g. en-GB, fr-FR) available from the resources, use `Resources.i18n.GetAllResourceCultures();`\n\nAnd finally, if you need to use a language different to the `CultureInfo.CurrentUICulture.Name`, you can use `Resources.Myi18nResources.SetCustomResourcesCulture(\"fr-FR\");`\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fukcoderj%2Fi18nstronglytypedcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fukcoderj%2Fi18nstronglytypedcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fukcoderj%2Fi18nstronglytypedcore/lists"}