{"id":23380558,"url":"https://github.com/flix-tech/stencil-i18n","last_synced_at":"2025-04-10T22:42:44.327Z","repository":{"id":34972143,"uuid":"193467501","full_name":"flix-tech/stencil-i18n","owner":"flix-tech","description":"static translations for stenciljs","archived":false,"fork":false,"pushed_at":"2023-01-06T01:55:22.000Z","size":767,"stargazers_count":17,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T22:56:47.190Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/flix-tech.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}},"created_at":"2019-06-24T08:41:34.000Z","updated_at":"2024-08-29T11:23:45.000Z","dependencies_parsed_at":"2023-01-15T11:15:10.686Z","dependency_job_id":null,"html_url":"https://github.com/flix-tech/stencil-i18n","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flix-tech%2Fstencil-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flix-tech%2Fstencil-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flix-tech%2Fstencil-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flix-tech%2Fstencil-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flix-tech","download_url":"https://codeload.github.com/flix-tech/stencil-i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312208,"owners_count":21082638,"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-12-21T20:16:44.862Z","updated_at":"2025-04-10T22:42:44.291Z","avatar_url":"https://github.com/flix-tech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/flix-tech/stencil-i18n.svg?branch=master)](https://travis-ci.org/flix-tech/stencil-i18n)\n\n# Static translations (Stencil plugin)\n\nGenerating staticly translated bundles.\n\n## Getting started\n\n```bash\nnpm i @flix-tech/stencil-i18n\n```\n\nconfigure it in `stencil.config.js`\n\n```javascript\nconst { i18n } = require('@flix-tech/stencil-i18n');\n\n...\n\nplugins: [\n    ...,\n    i18n({\n      functionName: 'i18n', // default value is i18n\n      dictionaryPath: 'src/i18n',\n      srcPath: 'src' // default value is src\n    })\n  ]\n```\n\nCreate the dummy function inside src folder to satisfy typescript and have a fallback.\n\n```typescript\nexport function i18n(key: string, params?: { [index: string]: string | number }): string {\n  return key;\n}\n```\n\nPut the translation files `messages.${locale}.json` into the `dictionaryPath` like specified in the stencil config.\nConfigure the build task in your `package.json` similar to the following.\n\n```\n\"build\": \"for lang in en de; do i18n_locale=$lang stencil build \u0026\u0026 mkdir -p dist-build/$lang \u0026\u0026 mv dist/* dist-build/$lang; done \u0026\u0026 mv dist-build/* dist/ \u0026\u0026 rm -R dist-build\"\n```\n\nBe sure to put the `i18n_locale` environment variable containing the same as `messages.${locale}.json` `locale`.\nUse the function you defined in `functionName` to translate.\nImport the dummy function defined before.\n\n```javascript\nconst param3 = 'bye';\n...\ni18n('TRANSLATION.KEY', {\n    param1: 1234,\n    param2: 'hello',\n    param3\n});\n```\n\n## Angular\n\nTo include the resulting components into your angular project do a dynamic import in the app component to have the components in the whole project but be able to also access the `LOCALE_ID`. `YOUR_COMPONENT_NAME` can be the npm name `@scope/package`.\n\n```typescript\nimport { Component, Inject, LOCALE_ID } from '@angular/core';\n\n@Component({\n  selector: 'app',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent {\n  constructor(@Inject(LOCALE_ID) locale: string) {\n    import(`\u003cYOUR_COMPONENT_NAME\u003e/dist/${locale}/loader`).then((webcomponent) =\u003e {\n      webcomponent.defineCustomElements(window);\n    });\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflix-tech%2Fstencil-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflix-tech%2Fstencil-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflix-tech%2Fstencil-i18n/lists"}