{"id":29203721,"url":"https://github.com/s00d/wasm-i18n","last_synced_at":"2025-07-02T14:40:08.045Z","repository":{"id":265905226,"uuid":"896836615","full_name":"s00d/wasm-i18n","owner":"s00d","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-09T06:27:51.000Z","size":8409,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T02:34:00.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s00d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","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-12-01T12:29:33.000Z","updated_at":"2024-12-09T06:27:54.000Z","dependencies_parsed_at":"2024-12-08T13:32:55.016Z","dependency_job_id":null,"html_url":"https://github.com/s00d/wasm-i18n","commit_stats":null,"previous_names":["s00d/wasm-i18n"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/s00d/wasm-i18n","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fwasm-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fwasm-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fwasm-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fwasm-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s00d","download_url":"https://codeload.github.com/s00d/wasm-i18n/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fwasm-i18n/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263158482,"owners_count":23422829,"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-07-02T14:39:57.009Z","updated_at":"2025-07-02T14:40:08.019Z","avatar_url":"https://github.com/s00d.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Here is the updated README based on your request for using the `I18n` class for importing and setting translations:\n\n---\n\n# wasm-i18n\n\nA Rust and WebAssembly project template for managing internationalization (i18n) translations in web applications using [wasm-pack](https://github.com/rustwasm/wasm-pack).\n\n## About\n\nThis project provides a set of functions to manage internationalization (i18n) translations in web applications. It allows you to set, get, delete, and update translations for different locales, as well as load translations from a remote URL.\n\n### 📦 Install\n\nYou can install the package via npm:\n\n```bash\nnpm install wasm-i18n\n```\n\nOr if you are using yarn:\n\n```bash\nyarn add wasm-i18n\n```\n\nMake sure you have [wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/) and [wasm-pack](https://github.com/rustwasm/wasm-pack) set up in your project to build and run this package.\n\n## 🚴 Usage\n\n### Example Usage\n\n```javascript\nimport { I18n } from 'wasm-i18n';\n\nlet i18n = new I18n();\n\nasync function run() {\n    await i18n.setTranslations('en', {\n        \"welcome\": \"Hello {username}\"\n    });\n\n    await i18n.setTranslations('en', {\n        \"test\": {\n            \"data\": '1111'\n        }\n    });\n\n    const tr = i18n.getTranslations('en');\n    console.log(tr);\n\n    const translation = i18n.getTranslation('en', \"welcome\");\n    console.log(translation);\n\n    const formatted = i18n.formatTranslation('en', 'welcome', { username: 'Alice' });\n    console.log(formatted);\n\n    document.getElementById('welcome-message').innerText = formatted;\n\n    const test = i18n.getTranslation('en', \"test.data\");\n    console.log(test);\n}\n\nrun();\n```\n\n## API Documentation\n\n### `setTranslations(locale: string, obj: any): void`\n\nSets translations for a specific locale. If translations already exist for the locale, they will be merged with the new translations.\n\n```javascript\ni18n.setTranslations('en', {\n    \"hello\": \"Hello\",\n    \"world\": \"World\"\n});\n```\n\n### `getTranslations(locale: string): any`\n\nGets all translations for a specific locale.\n\n```javascript\nconst translations = i18n.getTranslations('en');\nconsole.log(translations);\n```\n\n### `delTranslations(locale: string): void`\n\nDeletes all translations for a specific locale.\n\n```javascript\ni18n.delTranslations('en');\n```\n\n### `delTranslation(locale: string, key: string): void`\n\nDeletes a specific translation key for a locale.\n\n```javascript\ni18n.delTranslation('en', 'hello');\n```\n\n### `getTranslation(locale: string, key: string): any`\n\nGets the translation for a specific key in a locale.\n\n```javascript\nconst translation = i18n.getTranslation('en', 'hello');\nconsole.log(translation);\n```\n\n### `hasTranslation(locale: string, key: string): boolean`\n\nChecks if a specific translation key exists in a locale.\n\n```javascript\nconst exists = i18n.hasTranslation('en', 'hello');\nconsole.log(exists);\n```\n\n### `hasLocale(locale: string): boolean`\n\nChecks if a specific locale exists.\n\n```javascript\nconst exists = i18n.hasLocale('en');\nconsole.log(exists);\n```\n\n### `formatTranslation(locale: string, key: string, args: any): string`\n\nFormats a translation string with provided arguments.\n\n```javascript\nconst formatted = i18n.formatTranslation('en', 'welcome', { username: 'Alice' });\nconsole.log(formatted);\n```\n\n### `loadTranslations(url: string): Promise\u003cvoid\u003e`\n\nLoads translations from a remote URL.\n\n```javascript\nawait i18n.loadTranslations('https://example.com/translations.json');\n```\n\n### `getAllLocales(): Promise\u003cArray\u003cstring\u003e\u003e`\n\nGets all available locales.\n\n```javascript\nconst locales = await i18n.getAllLocales();\nconsole.log(locales);\n```\n\n### `getAllTranslationsForLocale(locale: string): Promise\u003cany\u003e`\n\nGets all translations for a specific locale.\n\n```javascript\nconst translations = await i18n.getAllTranslationsForLocale('en');\nconsole.log(translations);\n```\n\n### `clearAllTranslations(): void`\n\nClears all translations.\n\n```javascript\ni18n.clearAllTranslations();\n```\n\n### `updateTranslation(locale: string, key: string, value: any): void`\n\nUpdates a specific translation key for a locale.\n\n```javascript\ni18n.updateTranslation('en', 'hello', 'Hello, World!');\n```\n\n### `getAllTranslations(): any`\n\nGets all translations for all locales.\n\n```javascript\nconst all_translations = i18n.getAllTranslations();\nconsole.log(all_translations);\n```\n\n### `hasKeyInTranslations(locale: string, key: string): boolean`\n\nChecks if a specific key exists in the translations for a locale.\n\n```javascript\nconst exists = i18n.hasKeyInTranslations('en', 'hello');\nconsole.log(exists);\n```\n\n### Getter Methods\n\n| Method         | Description                                         | Example                                                                                                           |\n|----------------|-----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|\n| `locales`      | Retrieves all available locales.                    | ```js let locales = i18n.locales; console.log(locales); // [\"en\", \"fr\", \"de\", ...] ```                            |\n| `translations` | Retrieves all translations for all locales.         | ```js let translations = i18n.translations; console.log(translations); // { \"en\": { \"hello\": \"Hello\" }, ... } ``` |\n\n\n## License\n\nLicensed under either of\n\n* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n---\n\nLet me know if you need further modifications!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs00d%2Fwasm-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs00d%2Fwasm-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs00d%2Fwasm-i18n/lists"}