{"id":18800115,"url":"https://github.com/heinthanth/ni18n","last_synced_at":"2025-04-09T16:19:06.690Z","repository":{"id":70851325,"uuid":"604455377","full_name":"heinthanth/ni18n","owner":"heinthanth","description":"Super Fast Nim Macros For Internationalization and Localization","archived":false,"fork":false,"pushed_at":"2023-03-01T14:17:25.000Z","size":75,"stargazers_count":30,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T16:18:55.493Z","etag":null,"topics":["i18n","internationalization","l10n","localization","macros","nim","nim-i18n","nim-lang"],"latest_commit_sha":null,"homepage":"https://heinthanth.github.io/ni18n/","language":"Nim","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/heinthanth.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":"2023-02-21T05:03:03.000Z","updated_at":"2025-03-09T13:45:14.000Z","dependencies_parsed_at":"2025-02-19T20:40:09.337Z","dependency_job_id":null,"html_url":"https://github.com/heinthanth/ni18n","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heinthanth%2Fni18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heinthanth%2Fni18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heinthanth%2Fni18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heinthanth%2Fni18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heinthanth","download_url":"https://codeload.github.com/heinthanth/ni18n/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065282,"owners_count":21041872,"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":["i18n","internationalization","l10n","localization","macros","nim","nim-i18n","nim-lang"],"created_at":"2024-11-07T22:17:41.867Z","updated_at":"2025-04-09T16:19:06.684Z","avatar_url":"https://github.com/heinthanth.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ni18n ( nim + i18n )\n\nSuper Fast Nim Macros For Internationalization and Localization. It can prevent missing locales, duplicated translation names and invalid string interpolation at compile-time. But implementation is super simple!\n\nI was attempting to create a programming language in our local language ( Myanmar ) and I realized that I need to develop interpreter with multi-language approach because terminals can't render our language properly and I need to use English until I have a proper custom monospace font. This is the main motivation of creating this package.\n\n## Installation\n\nYou can add package name or repo URL to `.nimble` file\n\n```nim\nrequires \"ni18n \u003e= 0.1.0\"\n```\n\n## Quick Start\n\nSuper simple, Super Fast. No runtime lookup for translation: all translations are compiled down to Nim functions ( except we still have a runtime `case` statement for `locale` to call locale-suffixed function we generated - see [Behind The Scene](#behind-the-scene) )\n\n```nim\nimport ni18n\n\ntype\n    Locale = enum\n        English\n        Chinese\n        Myanmar\n\ni18nInit Locale, true:\n    hello:\n        # translations can be string literal\n        English = \"Hello, $name!\"\n        Chinese = \"你好, $name!\"\n        Myanmar = \"မင်္ဂလာပါ၊ $name ရေ။\"\n    ihaveCat:\n        English = \"I've many cats.\"\n        Chinese = \"我有很多小猫。\"\n        Myanmar = \"ငါ့ဆီမှာ ကြောင် အများကြီးရှိတယ်။\"\n        # translation definition can have sub-translation definition\n        withCount:\n            # translations can be lambda / closure\n            English = proc(count: int): string =\n                case count\n                of 0: \"I don't have a cat.\"\n                of 1: \"I have one cat.\"\n                else: \"I have \" \u0026 $count \u0026 \" cats.\"\n            Chinese = proc(count: int): string =\n                proc translateCount(count: int): string =\n                    case count\n                    of 2: \"二\"\n                    of 3: \"三\"\n                    of 4: \"四\"\n                    of 5: \"五\"\n                    else: $count # so on ...\n\n                return case count\n                    of 0: \"我没有猫。\"\n                    of 1: \"我有一只猫。\"\n                    else: \"我有\" \u0026 translateCount(count) \u0026 \"只猫。\"\n            Myanmar = proc(count: int): string =\n                proc translateCount(count: int): string =\n                    case count\n                    of 2: \"နှစ်\"\n                    of 3: \"သုံး\"\n                    of 4: \"လေး\"\n                    of 5: \"ငါး\"\n                    else: $count # so on ...\n\n                return case count\n                    of 0: \"ငါ့မှာ ကြောင်တစ်ကောင်မှ မရှိဘူး။\"\n                    of 1: \"ငါ့မှာ ကြောင်တစ်ကောင် ရှိတယ်။\"\n                    else: \"ငါ့မှာ ကြောင်\" \u0026 translateCount(count) \u0026 \"ကောင် ရှိတယ်။\"\n\n# prints \"你好, 黄小姐!\". This function behave the same as `strutils.format`\necho hello(Chinese, \"name\", \"黄小姐\")\n\n# prints 我有猫\necho ihaveCat(Chinese)\n\n# prints 我有五只猫\necho ihaveCat_withCount(Chinese, 5)\n\n# or like this ( because Nim compiler is smart! )\necho ihaveCatWithCount(Chinese, 5)\n\n# print ငါ့မှာ ကြောင်သုံးကောင် ရှိတယ်။\"\necho ihaveCatWithCount(Myanmar, 3)\n\n# compiler error here since each function is generated with the same signature from lambda\necho ihaveCat_withCount(Chinese, \"some str\") \n```\n\n## Behind the Scene\n\nImagine u write this code:\n\n```nim\ntype\n    Locale = enum\n        English\n        Chinese\n\ni18nInit Locale, true:\n    hello:\n        English = \"Hello, $name!\"\n        Chinese = \"你好, $name!\"\n```\n\nMagic macro will convert that code into this:\n\n```nim\ntype\n    Locale = enum\n        English\n        Chinese\n\nproc hello_English(args: varargs[string, `$`]): string {.inline.} =\n    format(\"Hello, $name!\", args)\n\nproc hello_Chinese(args: varargs[string, `$`]): string {.inline.} =\n    format(\"你好, $name!\", args)\n\nproc hello*(locale: Locale, args: varargs[string, `$`]): string {.inline.} =\n    case locale\n    of English: hello_English(args)\n    of Chinese: hello_Chinese(args)\n```\n\nSo, we have just locale runtime check, but since that's enum, we're still going fast!\n\n## Roadmap / Todos\n\n- [ ] set locale at compile time for multiple ( single locale ) binaries\n- [ ] write extensive test cases\n\n## Contribution and Other\n\nContributions, Ideas are welcome! For now, we're missing extensive test cases.\n\n## License\n\nni18n is licensed under MIT License. See [LICENSE](LICENSE) for more.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheinthanth%2Fni18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheinthanth%2Fni18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheinthanth%2Fni18n/lists"}