{"id":17761679,"url":"https://github.com/pathoschild/smapi-modtranslationclassbuilder","last_synced_at":"2025-05-12T20:47:27.889Z","repository":{"id":55371703,"uuid":"297806165","full_name":"Pathoschild/SMAPI-ModTranslationClassBuilder","owner":"Pathoschild","description":"Autogenerate a strongly-typed class to access i18n translation files from your SMAPI mod code.","archived":false,"fork":false,"pushed_at":"2024-08-21T02:17:06.000Z","size":71,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-15T11:47:02.667Z","etag":null,"topics":[],"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/Pathoschild.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2020-09-23T00:23:43.000Z","updated_at":"2025-01-09T14:17:02.000Z","dependencies_parsed_at":"2024-08-21T03:05:42.466Z","dependency_job_id":null,"html_url":"https://github.com/Pathoschild/SMAPI-ModTranslationClassBuilder","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pathoschild%2FSMAPI-ModTranslationClassBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pathoschild%2FSMAPI-ModTranslationClassBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pathoschild%2FSMAPI-ModTranslationClassBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pathoschild%2FSMAPI-ModTranslationClassBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pathoschild","download_url":"https://codeload.github.com/Pathoschild/SMAPI-ModTranslationClassBuilder/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253819412,"owners_count":21969352,"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-26T19:42:42.526Z","updated_at":"2025-05-12T20:47:27.856Z","avatar_url":"https://github.com/Pathoschild.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"**ModTranslationClassBuilder** autogenerates a strongly-typed class to access [`i18n`\ntranslation files](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Translation)\nfrom your [SMAPI](https://smapi.io/) mod code.\n\n## Contents\n* [Why does this exist?](#why-does-this-exist)\n* [Usage](#usage)\n  * [First-time setup](#first-time-setup)\n  * [Conventions](#conventions)\n* [Customization](#customization)\n* [See also](#see-also)\n\n## Why does this exist?\n### Without the package\nMods use code like this to read their translations:\n```cs\nstring text = helper.Translation.Get(\"range-value\", new { min = 1, max = 5 });\n```\n\nUnfortunately there's no validation at this point; if the key is `range` (not `range-value`) or the\ntoken name is `minimum` (not `min`), you won't know until you test that part of the mod in-game and\nsee an error message.\n\nThat also means that after changing the translation files, you need to manually search the code for\nanywhere that referenced the translations to update them. That gets pretty tedious with larger\nmods, which might have hundreds of translations used across dozens of files.\n\n### With the package\n\nThis package lets you write code like this instead:\n```cs\nstring text = I18n.RangeValue(min: 1, max: 5);\n```\n\nSince it's strongly typed, it's validated immediately as you type. For example, if you accidentally\ntyped `I18n.RangeValues` instead, you'll see an immediate error that `RangeValues` doesn't exist\nwithout needing to test it in-game (or even compile the mod).\n\nSee the [test mod](TestMod) for an example of the generated class in an actual mod.\n\n## Usage\n### First-time setup\n1. [Install the NuGet package](https://www.nuget.org/packages/Pathoschild.Stardew.ModTranslationClassBuilder).\n2. In your mod's `Entry` method, add this line:\n   ```cs\n   I18n.Init(helper.Translation);\n   ```\n\nThat's it! Now you can immediately use `I18n` anywhere in your mod code. The class will be updated\nautomatically whenever your `i18n/default.json` file changes.\n\n### Conventions\n* The class uses your project's root namespace by default (you can [change that](#customization)\n  if needed).\n* Translation keys are converted to CamelCase, with `.` changed to `_` to help group categories.\n\n  For example:\n\n  key in `i18n/default.json` | method\n  -------------------------- | --------------------------\n  `ready`                    | `I18n.Ready()`\n  `ready-now`                | `I18n.ReadyNow()`\n  `generic.ready-now`        | `I18n.Generic_ReadyNow()`\n\n## Customization\nYou can configure the `I18n` class using a `\u003cPropertyGroup\u003e` section in your mod's `.csproj` file.\nEach property must be prefixed with `TranslationClassBuilder_`. For example, this changes the class\nname to `Translations`:\n\n```xml\n\u003cPropertyGroup\u003e\n   \u003cTranslationClassBuilder_ClassName\u003eTranslations\u003c/TranslationClassBuilder_ClassName\u003e\n\u003c/PropertyGroup\u003e\n```\n\nMain options:\n\nargument         | description | default value\n---------------- | ----------- | ------------\n`ClassName`      | The name of the generated class. | `I18n`\n`Namespace`      | The namespace for the generated class. | _project's root namespace_\n\nAdvanced options:\n\nargument         | description | default value\n---------------- | ----------- | ------------\n`ClassModifiers` | The [access modifiers](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) to apply to the generated class (e.g. to make it public). | `internal static`\n`CreateBackup`   | Whether to add a backup of the generated class to the project folder in a `Generated` subfolder. If it's disabled, the generated file will be hidden and excluded from source control. | `false`\n\n## See also\n* [Release notes](release-notes.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpathoschild%2Fsmapi-modtranslationclassbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpathoschild%2Fsmapi-modtranslationclassbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpathoschild%2Fsmapi-modtranslationclassbuilder/lists"}