{"_id":"@sherby/sherby-localize","_rev":"1-351c8f32687c58c368c4e35b48f70c06","name":"@sherby/sherby-localize","dist-tags":{"latest":"2.0.0-rc.1"},"versions":{"2.0.0-rc.1":{"name":"@sherby/sherby-localize","flat":true,"version":"2.0.0-rc.1","description":"Mixin to localize Polymer components","author":{"name":"Benjamin Rancourt","email":"benjamin.rancourt@usherbrooke.ca"},"main":"sherby-localize-mixin.html","scripts":{"format":"npm-run-all format:*","format:js":"eslint . --ext js --fix","format:json":"eslint . --ext json --fix","format:markdown":"eslint . --ext md --fix","format:polymer":"polymer lint --fix","lint":"npm-run-all lint:*","lint:js":"eslint . --ext js","lint:json":"eslint . --ext json","lint:markdown":"eslint . --ext md","lint:polymer":"polymer lint","test":"polymer test"},"keywords":["format","i18n","internationalization","l10n","language","locale","localization","localize","mixin","polymer","sherby","translate","translation","web-components","webcomponents"],"repository":{"type":"git","url":"git+https://github.com/SherbyElements/sherby-localize.git"},"bugs":{"url":"https://github.com/SherbyElements/sherby-localize/issues"},"license":"MIT","homepage":"https://github.com/SherbyElements/sherby-localize","dependencies":{"@polymer/app-localize-behavior":"^3.0.0-pre.1","@polymer/polymer":"^3.0.0-pre.1","@sherby/sherby-nested-property":"^2.0.0-rc.1","@udeselements/udes-language-mixin":"^3.0.0-rc.1"},"devDependencies":{"@polymer/iron-demo-helpers":"^3.0.0-pre.12","@webcomponents/webcomponentsjs":"^2.0.0","wct-browser-legacy":"^1.0.0","eslint-config-udes":"^0.2.1","npm-run-all":"^4.1.2"},"gitHead":"be764c6eb42506e7e2600e74ea4e4eac9cc3190f","_id":"@sherby/sherby-localize@2.0.0-rc.1","_npmVersion":"6.0.1","_nodeVersion":"9.5.0","_npmUser":{"name":"ranb2002","email":"benjamin.rancourt@usherbrooke.ca"},"dist":{"integrity":"sha512-CIokysYh5NOEF5YZNYsd9G7gMOLOusbHrMvkcT44Gmjjz8ilGoDaDNgLDl6grv+54f0j7U52pqLMYoSdYyNyXQ==","shasum":"91d350adb2b1afdb604789580a7ce054ea9f53ae","tarball":"https://registry.npmjs.org/@sherby/sherby-localize/-/sherby-localize-2.0.0-rc.1.tgz","fileCount":6,"unpackedSize":14775,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbAb7uCRA9TVsSAnZWagAAPvcP/incsVYTRhGRqFVn1/iz\nAwG0xAplsWhAPI2pDjqI1ugBXpOj8+Kr0+ZYFJ1y4EvUJifHqyqu2ESKmK4U\nGkQiGMT/lPWk8RZT0KQ+ktGxRSLf1ljSYKOcIyyv5Coc6uv9lRl4TVeD1N+b\nDATCNBpdtfPEvzHts6MPwQNT6YsaQOeisKtqHL7zRzPqlVNu/L3fGK7Wsbwy\nmO5zpJUxHttkKsb9Z6za87J/OXzziK05YyMqYk0uQ4P5lPHT87gdigUsFyOS\n6OSSwfBZqe1uUT6U8kRPPo1A1r3XsYalVsLFjF4YrbBaWiVpc/Xv1J8jrlBv\nTOCkDTOTzbxa+rfTqbc3kfnleGe78EC/rt9IMBJMQXyF/rRqi+R+RRNHHOeh\nlB8dUBCUGbkutBJwiWBGQebfIwWijSdjzUwrOs7Sy4R2d/JBs8oUFOtpvArY\n83NqLYg3rICWVLzH/9rloXvp0+Q1ekZUFEjbS8e0s1Fu7LZG/3ilI+LLU8Jo\nxICXZw1+9QiYTPcrgRpl7443yHI1VPw7jpd8jy5fbVlBnaHpsetxSh8Pt48B\nw6FMeg0fnnl/rpFma559bqB9RPRW3uHaQ2B4jx/rgIYxyru39qAUcbP6GU6i\nV2H+u/FwR6LGfPRHX/m6POVb7TQQyGXMJvsIqNrHoGrOp/n2uSDeTtPKTxA3\ndOGC\r\n=/8uw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDbe+NaPASRK60iOGytfVB87SeY7nlDRnx8hBflP7p6BAIhAJ+goKTjl6oc7LER+yA6Lk/J5t5TfSGjGEwYTXMS3hnR"}]},"maintainers":[{"name":"ranb2002","email":"benjamin.rancourt@usherbrooke.ca"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sherby-localize_2.0.0-rc.1_1526841068723_0.2747858728374195"},"_hasShrinkwrap":false}},"time":{"created":"2018-05-20T18:31:08.336Z","2.0.0-rc.1":"2018-05-20T18:31:08.832Z","modified":"2022-04-06T23:13:08.236Z"},"maintainers":[{"name":"ranb2002","email":"benjamin.rancourt@usherbrooke.ca"}],"description":"Mixin to localize Polymer components","homepage":"https://github.com/SherbyElements/sherby-localize","keywords":["format","i18n","internationalization","l10n","language","locale","localization","localize","mixin","polymer","sherby","translate","translation","web-components","webcomponents"],"repository":{"type":"git","url":"git+https://github.com/SherbyElements/sherby-localize.git"},"author":{"name":"Benjamin Rancourt","email":"benjamin.rancourt@usherbrooke.ca"},"bugs":{"url":"https://github.com/SherbyElements/sherby-localize/issues"},"license":"MIT","readme":"[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/SherbyElements/sherby-localize)\n[![Build status](https://travis-ci.org/SherbyElements/sherby-localize.svg?branch=master)](https://travis-ci.org/SherbyElements/sherby-localize)\n\n# Sherby.LocalizeMixin\nIf you want to **translate**, to **localize** your application or simply only \n**regroup** all static texts, the `Sherby.LocalizeMixin` can help you.\n\nThe mixin internally use a [fork][2] of [AppLocalizeBehavior][3] to wraps the\n[Format.js][4] library with [Chrome.i18n][5] translation files. The \n*Chrome.i18n* format allow to add an optional `description` associated with \nthe translation (`message`), to give an additional context to translators.\n\nBy exemple, a *locales/en-CA.json* file:\n```json\n{\n  \"meat-toppings\": {\n    \"description\": \"A pizza is nothing without meat.\",\n    \"message\": \"Meat Toppings\",\n  }\n}\n```\n\nIf you want to have **nested** localization files, as below, you simply need\nto provide all keys of the nested object, separate by **.** (delimiter by \ndefault). By exemple, the key `meat-toppings.bacon-pieces` will provide the \ncorrect translation (Bacon Pieces) for the following json file:\n\n```json\n{\n  \"meat-toppings\": {\n    \"bacon-pieces\": {\n      \"description\": \"Bacon is life!\",\n      \"message\": \"Bacon Pieces\"\n    }\n  }\n}\n```\n\nAlso, as this mixin use the *[UdeS.LanguageMixin][1]*, the localized file \nassociated with the current language is dynamically loaded and the localised \ntexts are automatically translated when the current language change.\n\n## Usage\n- Add the `@sherby/sherby-localize` dependency to your projet:\n  ```bash\n  npm install @sherby/sherby-localize\n  ```\n\n- Create the locales directory near the component you want localized\n  and add the localize files:\n\n  *locales/en-CA.json*\n  ```json\n  {\n    \"bacon-pieces\": {\n      \"description\": \"Bacon is life!\",\n      \"message\": \"Bacon Pieces\"\n    }\n  }\n  ```\n\n  *locales/fr.json*\n  ```json\n  {\n    \"bacon-pieces\": {\n      \"description\": \"Bacon is life!\",\n      \"message\": \"Morceaux de bacon\"\n    }\n  }\n  ```\n\n- Use it\n    ```javascript\n    // Import the `SherbyLocalizeMixin` inside the component you want localized\n    import { SherbyLocalizeMixin } from '@sherby/sherby-localize/sherby-localize-mixin.js';\n    import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';\n\n    /* eslint-disable no-unused-vars */\n\n    // Apply the mixin to your element class\n    /**\n     * @customElement\n     * @polymer\n     * @extends {PolymerElement}\n     * @appliesMixin SherbyLocalizeMixin\n     */\n    class MyElement extends SherbyLocalizeMixin(PolymerElement) {\n      static get template() {\n        // Use the `localize` function to translate all texts\n        return html`\n          <h2>[[localize('meat-toppings')]]</h2>\n        `;\n      }\n\n      /**\n       * Get the localized bacon pieces string.\n       * @param {Function} localize Localize function.\n       * @return {String} Localized bacon pieces.\n       */\n      getLocalizedBaconPieces(localize) {\n        return localize('meat-toppings.bacon-pieces') || '';\n      }\n    }\n    ```\n\n## Demo\n<!--\n```\n<custom-element-demo>\n  <template>\n    <link rel=\"import\" href=\"demo/sherby-localize-demo.html\">\n    <next-code-block></next-code-block>\n  </template>\n</custom-element-demo>\n```\n-->\n```html\n<sherby-localize-demo></sherby-localize-demo>\n```\n\n## Language aware with UdeS.LanguageMixin\nIf you want your component to be aware of the current language only,\nyou should take a look on *[UdeSLanguageMixin][1]*, a mixin used by \n`SherbyLocalizeMixin`.\n\n## Thanks\nSpecial thanks to the [Collaborne team](https://github.com/Collaborne) for his [app-localize-chrome-i18n-mixin](https://github.com/Collaborne/app-localize-chrome-i18n-mixin) mixin that inspired me for this mixin.\n\n[1]: https://www.webcomponents.org/element/UdeSElements/udes-language-mixin \"UdeSLanguageMixin\"\n[2]: https://github.com/Collaborne/app-localize-behavior#fix/103 \"Fix made by Collaborne team\"\n[3]: https://github.com/PolymerElements/app-localize-behavior \"Polymer.AppLocalizeBehavior\"\n[4]: https://formatjs.io/ \"Format.js\"\n[5]: https://developer.chrome.com/apps/i18n \"chrome.i18n\"\n","readmeFilename":"README.md"}