{"id":30759190,"url":"https://github.com/Atoen/TextLocalizer","last_synced_at":"2025-09-04T12:03:30.886Z","repository":{"id":263680302,"uuid":"888977910","full_name":"Atoen/TextLocalizer","owner":"Atoen","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-14T19:51:00.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-22T03:45:40.726Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Atoen.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":"2024-11-15T11:21:14.000Z","updated_at":"2024-12-13T18:33:21.000Z","dependencies_parsed_at":"2024-12-13T19:32:23.241Z","dependency_job_id":"ece136fa-2eea-4d89-805a-61b5db803153","html_url":"https://github.com/Atoen/TextLocalizer","commit_stats":null,"previous_names":["atoen/textlocalizer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Atoen/TextLocalizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atoen%2FTextLocalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atoen%2FTextLocalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atoen%2FTextLocalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atoen%2FTextLocalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Atoen","download_url":"https://codeload.github.com/Atoen/TextLocalizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atoen%2FTextLocalizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273605066,"owners_count":25135678,"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-09-04T02:00:08.968Z","response_time":61,"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":[],"created_at":"2025-09-04T12:01:41.618Z","updated_at":"2025-09-04T12:03:30.877Z","avatar_url":"https://github.com/Atoen.png","language":"C#","funding_links":[],"categories":["Contributors Welcome for those"],"sub_categories":["1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category"],"readme":"# TextLocalizer\nA source-generated text translation provider using YAML files.\n\n## Setup\n\n### 1. Create Translation Files\n\nFirst, create the YAML (`.yaml` or `.yml`) files containing the translations.\nThe keys must be valid C# identifiers.\n\n```yaml\n# Blank and comment lines are ignored.\n# The ordering of keys does not need to match between files.\nhello_world: Hello, World!\ngoodbye: Goodbye.\n\n# Quoted values (useful for special characters or preserving whitespace)\nquoted: \"quoted: value!\"\nquoted2: 'some other value'\n```\n\n### 2. Include Localization Files in the Build\n\nEnsure that the YAML files containing localization data are included in the build process.\nAdd the following configuration to your project file (`.csproj`):\n\n```xml\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n    \u003cPropertyGroup\u003e\n        ...\n    \u003c/PropertyGroup\u003e\n\n    \u003cItemGroup\u003e\n        \u003cPackageReference Include=\"TextLocalizer\" Version=\"1.2.0\" /\u003e\n    \u003c/ItemGroup\u003e\n\n    \u003cItemGroup\u003e\n        \u003cAdditionalFiles Include=\"path\\to\\english.yml\" /\u003e\n        \u003cAdditionalFiles Include=\"path\\to\\other.yaml\" /\u003e\n    \u003c/ItemGroup\u003e\n\u003c/Project\u003e\n```\n\n### 3. Create Provider Classes\n\nCreate provider classes for each language you want to support.\nExactly one of these classes should be marked as the default language.\n\n```csharp\nusing TextLocalizer;\n\n[TranslationProvider(Filename = \"english.yml\", IsDefault = true)]\npublic partial class EnglishTextProvider;\n\n[TranslationProvider(Filename = \"other.yaml\")]\npublic partial class OtherTextProvider;\n```\n\nFinally, create the class providing the correct localized keys:\n\n```csharp\nusing TextLocalizer;\nusing TextLocalizer.Types;\n\n// You can represent the languages in any way you like.\npublic enum SupportedLanguage\n{\n    English,\n    Other\n}\n\n// The accessors are nescessary for the localization to work\n[LocalizationTable(\n    CurrentProviderAccessor = nameof(Provider),\n    DefaultProviderAccessor = nameof(DefaultProvider),\n    TableName = \"R\", // Defaults to \"Table\"\n    GenerateDocs = true, // Adds XML docs with translations for each key (enabled by default)\n    IdClassName = \"R\" // Set valid identifier to generate class with ids\n)]\npublic partial class Localization\n{\n    // Caching the providers might be useful\n    private readonly Dictionary\u003cSupportedLanguage, ILocalizedTextProvider\u003e _textProviders = new();\n    \n    public static SupportedLanguage DefaultLanguage { get; set; } = SupportedLanguage.English;\n    public SupportedLanguage Language { get; set; } = DefaultLanguage;\n    \n    // Using the generated id class\n    public string StringResource(StringResourceId id) =\u003e R[id];\n\n    public string StringResource(StringResourceId id, object? arg0)\n    {\n        return string.Format(R[id], arg0);\n    }\n    \n    private ILocalizedTextProvider Provider =\u003e GetLanguageProvider(Language);\n    private ILocalizedTextProvider DefaultProvider =\u003e GetLanguageProvider(DefaultLanguage);\n    \n    // You can implement custom logic to determine which provider to use\n    private ILocalizedTextProvider GetLanguageProvider(SupportedLanguage language)\n    {\n        if (_textProviders.TryGetValue(language, out var provider))\n        {\n            return provider;\n        }\n\n        var newProvider = CreateProvider(language);\n        _textProviders[language] = newProvider;\n\n        return newProvider;\n    }\n    \n    private static ILocalizedTextProvider CreateProvider(SupportedLanguage language) =\u003e language switch\n    {\n        SupportedLanguage.English =\u003e new EnglishTextProvider(),\n        SupportedLanguage.Other =\u003e new OtherTextProvider(),\n        _ =\u003e throw new ArgumentOutOfRangeException(nameof(language))\n    };\n}\n\n```\n\n## Usage\n\n```csharp\nvar localization = new Localization();\n\n// Accessing id of specific keys\nvar farewellId = R.farewell;\nConsole.WriteLine(localization.R[farewellId]);\n\n// Using the helper method to format translations\nvar message = localization.StringResource(R.templated, true);\nConsole.WriteLine(message);\n\nConsole.WriteLine(localization.R.greetings);\n\nlocalization.SetLanguage(SupportedLanguage.Other);\nConsole.WriteLine(localization.R.greetings);\n```\n\n## Untranslatable and Missing Keys\n\nThe generator emits warnings about missing or extra keys in localized dictionaries.\nIf a key is not found in the localized file, the value from the default file is used instead.\n\n```\n0\u003epolish.yml(1,1): Warning TL001 : The key 'missing_key' is missing its translation in polish.yml file\n0\u003epolish.yml(6,1): Warning TL002 : File polish.yml contains key 'extra_key', which is not present in the main translations file\n```\n\nYou can mark the key in the main dictionary file as untranslatable with a comment:\n```yaml\nspecial_key: Special value # untranslatable\n```\n\nWhen such a key is found in a localized file, its value is ignored, and another warning is emitted:\n```\n0\u003epolish.yml(7,1): Warning TL003 : File polish.yml contains key 'untranslated_key', which is marked as untranslatable\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAtoen%2FTextLocalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAtoen%2FTextLocalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAtoen%2FTextLocalizer/lists"}