{"_id":"elm-i18next-gen","_rev":"4-6d968f318e3422fb38e07a6cfec934ed","name":"elm-i18next-gen","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.1":{"name":"elm-i18next-gen","version":"1.0.1","description":"Code generation for elm-i18next","main":"index.js","repository":{"type":"git","url":"git+https://github.com/yonigibbs/elm-i18next-gen.git"},"scripts":{"test":"mocha && npm run generate-sample-translations && npm run elm-format-validate && npm run elm-test-validate","test-watch":"mocha --watch","lint":"eslint **/*.js","lint-fix":"eslint --fix **/*.js","generate-sample-translations":"bin/elm-i18next-gen -s test/resources/sample.json -t elm-sandbox/src -o","elm-format-validate":"elm-format elm-sandbox/src/ --validate","elm-test-validate":"cd elm-sandbox && elm-test && cd -"},"author":{"name":"Yoni Gibbs"},"license":"ISC","bin":{"elm-i18next-gen":"bin/elm-i18next-gen"},"devDependencies":{"@types/chai":"^4.2.7","@types/command-line-args":"^5.0.0","@types/mocha":"^5.2.7","chai":"^4.2.0","elm":"^0.19.1-3","elm-format":"^0.8.2","elm-test":"^0.19.1-revision2","eslint":"^6.8.0","eslint-config-standard":"^14.1.0","eslint-plugin-import":"^2.20.0","eslint-plugin-node":"^11.0.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","mocha":"^7.0.0","np":"^5.2.1"},"dependencies":{"commander":"^4.1.0","fs-extra":"^8.1.0"},"gitHead":"37fb9ffecf87a09c190fe741e2e01274bcabf348","bugs":{"url":"https://github.com/yonigibbs/elm-i18next-gen/issues"},"homepage":"https://github.com/yonigibbs/elm-i18next-gen#readme","_id":"elm-i18next-gen@1.0.1","_nodeVersion":"13.5.0","_npmVersion":"6.13.6","dist":{"integrity":"sha512-mXeDBtolc1YKVGTuYg9LvT8QkBaHMBpYViY6OZNwm+UeAEvg5b+U5Q19j8gtpFoOW0weJImNUcHjuhFxOvTOeQ==","shasum":"7bcc9a4f754a92963eecd294be052133bbcde1ff","tarball":"https://registry.npmjs.org/elm-i18next-gen/-/elm-i18next-gen-1.0.1.tgz","fileCount":13,"unpackedSize":38343,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeMCW/CRA9TVsSAnZWagAAzfUP/jsEQv60FAafZMsn+raB\n1fmxOTsvDxCFS1DfR3iO3UDoq6FnMvQEgQMOeitBaR6q9DnrFghF0tXIpdHr\nl5IueNQC+4dBnixtbqGEzsN5A1ft1VllrcaFsPADZC3xMB2IBR4ar7vR5TQn\nNtO9BuM4MekmQRA/2cMFacqZIBAr06KjOSolTr/WIky9avdbOpcN52byP6Jj\nXdd35RxjqTDTMHlxuuNvnmCEIPpSr5iPg9TgprWLEVgDZj6VMSuqPm+EnwCd\nki0odIAG9ujEPwQWtEYgQXQvRys+zHKweqCiZxWAM4/WerCyvVNHr73CHzm6\ngu7L3TK1I/0svYJYBTV7r9nBTY018i+TAko7DLILTiJkXNtjxJrDj7FUXEUr\ntCB5fJu0IYuHJKnu9OTIjgm954r246S43w4n/RQ2n9O+zbtD+7cQ5vp2OGKJ\nqYa7Ruh1TO0cW66zs4POXadFdQJ3Au2fGstcwIa26dXQ8xRVFFs0spW8SUu9\nkAmbCFnP+CSNR8dcFBKqcrmX6R7Ry0qZiwUKAQjLZ8687wDMiE+Ita0Mn1CR\nK0UdCIc3BjHlOixDozpxVq/QsbLbFF7Mlip/Tm/opXHzsUG2uXnnrLXzOikS\nCPF0SXg4Ug8SQ6BbIaXLGuVhEuuy1vrs4rCRICgW6YiHvL4d3mOCRUA4PYhI\noTe7\r\n=drql\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICDpnu5LrcG2cgq+Ky7NxxcWlAQNP3fUYlXrFUl5ebPkAiEAgqeC5u/LFWa6nj/+vTvFbizsw46uxwWQUNuIr3+ZiPY="}]},"maintainers":[{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"}],"_npmUser":{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/elm-i18next-gen_1.0.1_1580213695258_0.7867681641421476"},"_hasShrinkwrap":false},"1.0.2":{"name":"elm-i18next-gen","version":"1.0.2","description":"Code generation for elm-i18next","main":"index.js","repository":{"type":"git","url":"git+https://github.com/yonigibbs/elm-i18next-gen.git"},"scripts":{"test":"mocha && npm run generate-sample-translations && npm run elm-format-validate && npm run elm-test-validate","test-watch":"mocha --watch","lint":"eslint **/*.js","lint-fix":"eslint --fix **/*.js","generate-sample-translations":"bin/elm-i18next-gen -s test/resources/sample.json -t elm-sandbox/src -o","elm-format-validate":"elm-format elm-sandbox/src/ --validate","elm-test-validate":"cd elm-sandbox && elm-test && cd -"},"author":{"name":"Yoni Gibbs"},"license":"ISC","bin":{"elm-i18next-gen":"bin/elm-i18next-gen"},"devDependencies":{"@types/chai":"^4.2.7","@types/command-line-args":"^5.0.0","@types/mocha":"^5.2.7","chai":"^4.2.0","elm":"^0.19.1-3","elm-format":"^0.8.2","elm-test":"^0.19.1-revision2","eslint":"^6.8.0","eslint-config-standard":"^14.1.0","eslint-plugin-import":"^2.20.0","eslint-plugin-node":"^11.0.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","mocha":"^7.0.0","np":"^5.2.1"},"dependencies":{"commander":"^4.1.0","fs-extra":"^8.1.0"},"gitHead":"2f07a0d0e002fe8cae5c7b7148d4c9d03b32c5ca","bugs":{"url":"https://github.com/yonigibbs/elm-i18next-gen/issues"},"homepage":"https://github.com/yonigibbs/elm-i18next-gen#readme","_id":"elm-i18next-gen@1.0.2","_nodeVersion":"13.5.0","_npmVersion":"6.13.6","dist":{"integrity":"sha512-wTwgfpr411ltVo5BanDuUZHyrIjlt+MGKb7W2b9aLejafgAL3Sh62Rb/fQE1X1zHg78tYokNgdS+ADMrAO6cTA==","shasum":"e563e6b021f904766e29bcdb2c05ed3e890fe662","tarball":"https://registry.npmjs.org/elm-i18next-gen/-/elm-i18next-gen-1.0.2.tgz","fileCount":13,"unpackedSize":38343,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeMCiCCRA9TVsSAnZWagAAGM8QAJmLZwj7l6dZHOlSvvFC\nlHpZBNmyiXk1j0ZzDrvj9M20W9+GzD4ZwpnytJgyfePtxFzylI9pQ5uTX3Wg\nYponjwmggkDaUWittC+xGIh02+nhTLxqIL39tNIFNs47MEe8YCJdFtHWNBMo\n45LlRWOpqbuP2pQgcN5IrRttHydOGvBqJpQTsKebtPEm4osdZE6Gz26WLjUH\n5flGhE+ooQONmI4HBZePVlrQGCFtdLElA5Hn/NJXc0dEiAMSAYPuh+GASf7Y\n9Fhf80ng1xyrD0F3Lfgc3I8rxuEPW9yKaJT0JZg9h6Fv3G+JKUh3gMp4V+n0\nxSt0vJ1MT/JpmflGY0QjTJ/bVZAM0elrsVke6Ag0mo3xvRS+Fcq5GVfNcg9M\nG9fu9UhyEznG1N04eNnyFs9PZ9GFexFnZfTokRmd9hmMnEvwFf//dUs90eNe\nWNF/Vs8m06DluAv0Cx93DSkGYWM3Si2TgWbbHGC2Qg6PX054dkxHfNEiZfvG\naRNQ3EzwT80cGp7ywt1Qf2SNtZhicwQ9RJ0WaMu7bHh+Kir0DbBxro9YjbcX\nwlD4F/926PgDBX7DremPYJf23ZnTMMkYlXqk9ZJM+CgVKxQDEKaSxR/G+PWv\nDoSKVfvjzSJD75su2vvIgrYtoohHF7yOlGvcdYsmCTw7/RbXIqDRrmLmJN0n\n+U42\r\n=nBlX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGifhBtGduF5XHPZNMpV0xdLdTsKiVBSa2fq1Y4b1sKrAiAf77uV+bSkFk0+lVgakEhSPfUh7zRCCYUXO9Sn/iIAdQ=="}]},"maintainers":[{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"}],"_npmUser":{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/elm-i18next-gen_1.0.2_1580214401735_0.1786697262248944"},"_hasShrinkwrap":false},"1.0.3":{"name":"elm-i18next-gen","version":"1.0.3","description":"Code generation for elm-i18next","main":"index.js","repository":{"type":"git","url":"git+https://github.com/yonigibbs/elm-i18next-gen.git"},"scripts":{"test":"mocha && npm run generate-sample-translations && npm run elm-format-validate && npm run elm-test-validate","test-watch":"mocha --watch","lint":"eslint **/*.js","lint-fix":"eslint --fix **/*.js","generate-sample-translations":"bin/elm-i18next-gen -s test/resources/sample.json -t elm-sandbox/src -o","elm-format-validate":"elm-format elm-sandbox/src/ --validate","elm-test-validate":"cd elm-sandbox && elm-test && cd -"},"author":{"name":"Yoni Gibbs"},"keywords":["elm","internationalization","internationalisation","i18n","i18next","elm-i18next"],"license":"ISC","bin":{"elm-i18next-gen":"bin/elm-i18next-gen"},"devDependencies":{"@types/chai":"^4.2.7","@types/command-line-args":"^5.0.0","@types/mocha":"^5.2.7","chai":"^4.2.0","elm":"^0.19.1-3","elm-format":"^0.8.2","elm-test":"^0.19.1-revision2","eslint":"^6.8.0","eslint-config-standard":"^14.1.0","eslint-plugin-import":"^2.20.0","eslint-plugin-node":"^11.0.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","mocha":"^7.0.0","np":"^5.2.1"},"dependencies":{"commander":"^4.1.0","fs-extra":"^8.1.0"},"gitHead":"0a6b8b8af13c05867f7f4a81d2ce3648d43785c8","bugs":{"url":"https://github.com/yonigibbs/elm-i18next-gen/issues"},"homepage":"https://github.com/yonigibbs/elm-i18next-gen#readme","_id":"elm-i18next-gen@1.0.3","_nodeVersion":"10.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-dGYnKs78KHOJ7ggjEdInkHajCTyd1iOckPaS6ANpM4w8KahCmwxA9K4WIhj6O3Myut1gW8i0LaLPAuZUaFOaCg==","shasum":"c7718305f305065443eb9cad67208c8738ed1349","tarball":"https://registry.npmjs.org/elm-i18next-gen/-/elm-i18next-gen-1.0.3.tgz","fileCount":13,"unpackedSize":38375,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeMVEdCRA9TVsSAnZWagAA6KUP/jDxASDhxC4OT70oQZMh\n6TYnDuLSyK69Ye+NSNdMwAe4+SMhk9mmGFz9fS9NbgOI+8+Afzi7JAeO4KFk\nbYhaY14H/PHjJ5iygzyY9EkUGRr98dnLCC32EpzqsUbyxE+F6oX03guRq5dB\nHufx2Gqobf0Ax89WJC3cXocxVsaMdYav/A5L1/Mw8dGv6x3d7sSZyuAyEgmu\nkuPkVTgXcA6RVACDCwM3QxjtT8Td4FbXZ1r2gfdWHCesyn9wSQu2Y+v6MZpj\ntod84jtbaDE/9PpMaYuwMW/XYPqt2tUE8IWYPlBb5L0LcqogPrZfKxsoCa8A\nFLiKoWXV55kQX8EnLFUDb8lhp5a3CwWHMVvaEs9IsbWbplHZsDzTzk3PMJHY\nu5WyqPZMlYgm2iILuhI+DDDz62kDmNLaRPXVmRQArrkDx4umRYZICeQSt8ya\nxLOFQDPrZB2HVJ6H8zox3xA42dIqtWurqJvnnFfcgP3H3kzY1o0l6zc2Fgd6\nNjcUa0VmMenj8x0cy3Ra1LicsFP6/qyLv6SnWAnE9GETujSj9EPJa42H/i13\n1ndVhMPXDMU65jRrpj8E3xx7Sq98mkYbkdPv310ira7k7QZ4cTGN5IdHxkT5\n004Lirhy2N7pw/0C++7p2fFB91j+x0T3DkAu/RhurBEYxIhZz/kmJapzsarR\nRtkQ\r\n=2Rz0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCWw9ou0St+6K2OxcJ0wyEfIpNhxNhiR9r7u4zClisuvQIgaHz6uldcVNG4eJqjMQSZWQq7nTuTz1qZ5B7QY8C1doQ="}]},"maintainers":[{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"}],"_npmUser":{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/elm-i18next-gen_1.0.3_1580290333111_0.9646043585338966"},"_hasShrinkwrap":false},"1.1.0":{"name":"elm-i18next-gen","version":"1.1.0","description":"Code generation for elm-i18next","main":"index.js","repository":{"type":"git","url":"git+https://github.com/yonigibbs/elm-i18next-gen.git"},"scripts":{"test":"mocha && npm run generate-sample-translations && npm run elm-format-validate && npm run elm-test-validate","test-watch":"mocha --watch","lint":"eslint **/*.js","lint-fix":"eslint --fix **/*.js","generate-sample-translations":"bin/elm-i18next-gen -s test/resources/sample.json -t elm-sandbox/src -o","elm-format-validate":"elm-format elm-sandbox/src/ --validate","elm-test-validate":"cd elm-sandbox && elm-test && cd -"},"author":{"name":"Yoni Gibbs"},"keywords":["elm","internationalization","internationalisation","i18n","i18next","elm-i18next"],"license":"ISC","bin":{"elm-i18next-gen":"bin/elm-i18next-gen"},"devDependencies":{"@types/chai":"^4.2.14","@types/command-line-args":"^5.0.0","@types/mocha":"^8.2.0","chai":"^4.2.0","elm":"^0.19.1-3","elm-format":"^0.8.4","elm-test":"^0.19.1-revision4","eslint":"^7.15.0","eslint-config-standard":"^16.0.2","eslint-plugin-import":"^2.22.1","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^5.0.0","mocha":"^8.2.1","np":"^7.0.0"},"dependencies":{"commander":"^7.0.0-2","fs-extra":"^9.0.1"},"gitHead":"cb407c3688c501fcb166bb14c3e102df9fdb7eb3","bugs":{"url":"https://github.com/yonigibbs/elm-i18next-gen/issues"},"homepage":"https://github.com/yonigibbs/elm-i18next-gen#readme","_id":"elm-i18next-gen@1.1.0","_nodeVersion":"14.8.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-wt6iG0toaAb6i4PoUNU4slMjC+XLSDBmXWbgUt9ENvossk6eJ3KjokJEejaYak448ST9D7p7NG2R86/6oeW5Lw==","shasum":"6060a40ba6d4e0844f377c674fe14dbac1340111","tarball":"https://registry.npmjs.org/elm-i18next-gen/-/elm-i18next-gen-1.1.0.tgz","fileCount":15,"unpackedSize":51100,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf3RTWCRA9TVsSAnZWagAAVjQQAJ3zeYJsGQgwIqxzfygx\n0Io8syz6BXR+eUgIE5FXlvhc1reYhEx6SV+I2raMtRNoct2W0sD2UEbk/834\nX0epEo0Fxhf5PMEmarj/fiAR28cPqp7BNwJ9yZn6l8dUJZwDgRlpzEmXQCwS\nIrW3Rb7x+cCGnsJjYCmaaVlPvDtRtxtXIYs4Ry1348Vh0S3UHMFqpv05zcXT\n9sgkUQ5+6sk0VK034II+Zglc+BOJBoK0JBHzkFDPPLZoiS7yECd/NONsktyv\nfGh9cVkZtLbmzz6AK+ebkCGvAeWoL3J1I7yykTMbijrjkMQNkgifu437oLiM\nMTb2xbrN4fARRYkjEuSrIYgW1Fc1Ztz4WaUdVkT2eMKjQPpUm8RqGAgOiHaq\ni9HjBDKmtwk12FVN8aRhEWzeyRT6WNeYPX/Ou5FS1K1hW2b38SQfY7g/O9+k\nI5bPGjslQrPI0MWSfq4UYNO2KiPk5J//sjdGM772HF9/+lDZ6rvbybeL78DY\nWs162kZmhvrKmc5zUezRfLrp2PYCaRuQu/jt2ViZ39J4BlRrih4QQW/H6TgV\nz1iQrLsC0/BXj8LGNikJBHsdXwtEAHmzE6seXihuER0D0z2kuSfWE7dMzXSO\nIHkIKT03dY5ZolDae+RFvPyqcRw4Mq+wA8axyMcSDjkyI/p8h4JEU+EnS9EI\nJZmh\r\n=krXh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEhybCC3h1pde3afNsdrs1ENcRxe6F6z/hLJzOSOLm4hAiB3S4Hg2Tjfxje7rEs2AOdt5RAyW3Dw7pG5uDSDM+XxRQ=="}]},"_npmUser":{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"},"directories":{},"maintainers":[{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/elm-i18next-gen_1.1.0_1608324309477_0.839986543739969"},"_hasShrinkwrap":false}},"time":{"created":"2020-01-28T12:14:55.257Z","1.0.1":"2020-01-28T12:14:55.404Z","modified":"2022-05-01T02:34:31.880Z","1.0.2":"2020-01-28T12:26:41.933Z","1.0.3":"2020-01-29T09:32:13.231Z","1.1.0":"2020-12-18T20:45:09.728Z"},"maintainers":[{"name":"yonigibbs","email":"yoni.gibbs.public@gmail.com"}],"description":"Code generation for elm-i18next","homepage":"https://github.com/yonigibbs/elm-i18next-gen#readme","repository":{"type":"git","url":"git+https://github.com/yonigibbs/elm-i18next-gen.git"},"author":{"name":"Yoni Gibbs"},"bugs":{"url":"https://github.com/yonigibbs/elm-i18next-gen/issues"},"license":"ISC","readme":"# Code Generation for [elm-i18next](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest)\n\n[![Actions Status](https://github.com/yonigibbs/elm-i18next-gen/workflows/Node%20CI/badge.svg)](https://github.com/yonigibbs/elm-i18next-gen/actions)\n\n## Overview\n\n`elm-i18next-gen` is a tool for handling internationalization in Elm projects. It combines type safety with dynamic\ntranslation loading, allowing for a smoother translation process and smaller bundles than some other solutions, while\nmaintaining type safety.\n\nThis tool generates code which uses\nthe [elm-i18next](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest)\npackage to read text values from a source JSON object. If a change is made to the source JSON object `elm-i18next-gen`\nensures the corresponding change required in the code is found at compile-time, not at runtime. This means you don't\nneed to worry about translations being out-of-sync with the code.\n\n## Pre-requisites\n\n`elm-i18next-gen` requires Node 10 or higher.\n\n## Installation\n\nInstall `elm-i18next-gen` from npm:\n\n```shell script\nnpm install --save-dev elm-i18next-gen\n```\n\n## Getting Started\n\nThis section assumes you are not already using the `elm-i18next` package. If this doesn't apply to you, please see the\n[next section](#adding-to-a-project-already-using-elm-i18next).\n\n1. Install `elm-i18next` by running this at the root of your project:\n    ```shell script\n    elm install ChristophP/elm-i18next\n    ```\n\n1. Create a JSON file containing your translations. There will one of these for each language you support, but\n   `elm-i18next-gen` only requires one (generally the one that you treat as your \"primary\" language, that you update as\n   you're writing the code). As an example, let's imagine your JSON file is called `translations.en.json` and looks as\n   follows:\n\n   ```json\n   {\n     \"welcome\": \"Welcome back, {{name}}\",\n     \"logout\": \"Click here to log out\"\n   }\n   ```\n\n1. Update the JavaScript code which initializes your Elm code and pass in the JSON from the file above in the `flags`,\n   e.g.:\n\n   ```js\n   Elm.Main.init({ flags: translations });\n   ```\n\n   Here, `translations` can either be a JavaScript object literal or a string containing the JSON. Typically this would\n   be fetched from somewhere, e.g.:\n\n   ```js\n   const translations = await fetch('/path/to/files/translations.en.json');\n   Elm.Main.init({ flags: translations });\n   ```\n\n   Alternatively it could be pre-rendered into the JavaScript on the server-side, or it can be fetched from within the\n   Elm code itself, as mentioned [here](https://github.com/ChristophP/elm-i18next/tree/master#fetching-translations).\n\n   The JavaScript code, or the server-side code generating the JavaScript, can choose the relevant translation file for\n   the current user. For example the server could do this based on the user's locale by interrogating the\n   [Accept-Language](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) HTTP header.\n\n1. Update your Elm code by creating a field in your model to store the translations, and initializing it with the data\n   from the `flags`, e.g.:\n\n   ```elm\n   import I18Next\n   import Json.Encode\n   import Json.Decode\n   \n   type alias Model = {\n       translations: I18Next.Translations\n   }\n   \n   init : Json.Encode.Value -> (Model, Cmd msg)\n   init flags =\n       case Json.Decode.decodeValue I18Next.translationsDecoder flags of\n           Ok translations ->\n               ( Model translations, Cmd.none )\n   \n           Err err ->\n               -- handle the error\n   ```\n\n1. Run `elm-i18next-gen` to generate functions that will provide access to the translations above. As an example, let's\n   imagine your project is structured as follows:\n\n   ```\n   my-project/\n   ├── src/\n   |   ├── index.html\n   |   ├── index.js\n   |   ├── Main.elm\n   ├── translations/\n   |   ├── translations.en.json\n   |   ├── translations.fr.json\n   ├── package.json\n   ├── elm.json\n   ```\n\n   From the root of the project (i.e. in the `my-project` folder in the example above) run the following:\n\n   ```shell script\n   npx elm-i18next-gen --source translations/translations.en.json --target src\n   ```\n\n   _(Note that if you run the command above more than once, it will fail. Simply add `--overwrite` to get round this.\n   See\n   [Command-line Arguments](#command-line-arguments) for more information.)_\n\n   This will create a file called `src/Translations.elm`. This is an Elm module that you can import into your code. In\n   this module there will be one function per translation in the JSON file. You can use it as shown below. (As an\n   example here let's assume there's a `username` field on the model.)\n\n   ```elm\n   import Translations\n   \n   view : Model -> Html Msg\n   view model =\n       div []\n           [ div [] [ text <| Translations.welcome model.translations model.username ]\n   ```\n\n### Adding to a project already using `elm-i18next`\n\nIf you are already using `elm-i18next` you can integrate `elm-i18next-gen` into your project quite easily. Install it as\nper the [installation instructions](#installation), and run it as explained in the last point above. You can now import\nthe generated `Translations.elm` module into your code and start using it instead of calling the existing functions\nfrom `elm-i18next`. You can either leave existing code as it is, or migrate it to use the new generated code:\nusing the the generated functions alongside the existing `elm-i18next` functions is fine.\n\nOne point to note is that the generated module is called `Translations`, but there's already a module in `elm-i8next` of\nthe same name. So when importing you'll need to use fully qualified imports or an alias to distinguish between the two.\n\n## Motivation\n\n_This section explains why `elm-i18next-gen` was written, and why you might want to use it. If you're not interested,\nand just want more detailed information on using it, skip to the [Usage](#usage) section below._\n\nIn Elm there are various approaches to solve the problem of internationalization, including\n[elm-i18n](https://github.com/iosphere/elm-i18n), [i18n-to-elm](https://github.com/dragonwasrobot/i18n-to-elm),\n[elm-i18n-module-generator](https://github.com/ChristophP/elm-i18n-module-generator) and\n[elm-i18next](https://github.com/ChristophP/elm-i18next). Each of these takes a different approach, and each is suited\nto slightly different use cases. For a recent project, I chose to use `elm-i18next-gen` for various reasons:\n\n* I didn't want to build a separate version of the app for each language.\n* I didn't want to pass the user's language around the model.\n* I didn't want to download the translations for every language to the user, when they only ever use one.\n* I didn't want to have to rebuild and redeploy the client code every time translations for a new language were added.\n\n`elm-i18next` ticks all the boxes above. The one thing I wanted that the package didn't give me is compile-time checking\nof my code against the source JSON object containing the translations. For example, say the JSON object contains this\ntranslation:\n\n```json\n{\n  \"greetName\": \"Hi {{name}}\"\n}\n```\n\nThe Elm code to call this would look as follows:\n\n```elm\ntr model.translations Curly \"greetName\" [ ( \"name\", \"Peter\" ) ]\n```\n\nHowever the following Elm code would also compile:\n\n```elm\ntr model.translations Curly \"gretName\" [ ( \"nam\", \"Peter\" ) ]\n```\n\nThere are two typos there, neither of which would be caught at compile time, leading to problems (though not exceptions:\nthis is Elm after all :relaxed:) when the page is rendered.\n\nTo solve this problem, `elm-i18next-gen` takes in a JSON file containing the translations, and generates a function for\neach string value. That function itself simply calls the `elm-i18next` package. The code in the application calls the\ngenerated functions rather than using `elm-i18next` directly.\n\nUsing the example above, the generated code for it would look as follows:\n\n```elm\ngreetName : Translations -> String -> String\ngreetName translations name =\n    tr translations Curly \"greetName\" [ ( \"name\", name ) ]\n```\n\nThe application code would then have the following:\n\n```elm\ngreetName model.translations \"Peter\"\n```\n\nNow if a developer types `gretName` the code won't compile. And as the placeholder `name` is now baked into the\ngenerated code, there isn't an opportunity for any mistakes there. Similarly if a new placeholder is added in the text:\nthe generated function will now require two parameters instead of one so the required change to the calling code will be\nspotted at compile time.\n\nAn important point here is that the generated code does not contain the actual translated value (e.g. `\"Hi {{name}}\"`).\nThese values are still read from the source JSON object at runtime. This means that as new languages are added, or as\nstring values are updated, the code doesn't have to change (unless of course the translation IDs or placeholders change)\n.\n\n## Usage\n\n`elm-i18next-gen` can be run directly using `npx` or by adding a new entry to the `scripts` section of `package.json`\nthen using `npm run`.\n\nTo run with `npx` execute this at the root of your project:\n\n```shell script\nnpx elm-i18next-gen ... [see below for args]\n```\n\nTo use `npm run` add this to `package.json`:\n\n```\n{\n  ...\n  \"scripts\": {\n    \"generate-translations\": \"elm-i18next-gen ... [see below for args]\"\n    ...\n```\n\nThen execute this at the root of your project:\n\n```shell script\nnpm run generate-translations\n```\n\n(The name of the script, in this example `generate-translations`, can be whatever you want.)\n\n### Command-line Arguments\n\nIn order to run, this `elm-i18next-gen` requires two command-line arguments to be supplied:\n\n* `--source` (short form `-s`): The source file containing the JSON which contains the translations.\n* `--target` (short form `-t`): The folder in which the source files are to be generated. Can be absolute or relative to\n  current folder.\n\nWithout these this tool cannot run.\n\nOptionally, the following arguments can also be supplied:\n\n* `--overwrite` (short form `-o`): Ensures that if the any of the target files exist, they will be overwritten. If this\n  argument isn't supplied and any of the target files exist, the process will abort. See the [Overwriting](#overwriting)\n  section below for further details.\n* `--watch` (short form `-w`): Watches the source file for changes and regenerates the code whenever it does.\n* `--fallback` (short form `-f`): Generates functions which receive a list of fallback languages. The generated\n  functions will use [tf](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next#tf) and\n  [trf](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next#trf) instead of\n  [t](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next#t) and\n  [tr](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next#tr).\n* `--type` (short form `-y`): Specifies what type of translation functions to use. In version 4.2.0 of `elm-i18next` a\n  new feature was added: the ability to replace placeholders with non-string values, typically `Html` values. This is\n  done using the [customTr](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next#customTr) and\n  [customTrf](https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next#customTrf) functions. If you\n  are using this version (or later) of `elm-i18next` then the `type` command-line argument can be used to tell\n  `elm-i18next-gen` to generate functions which use this feature. There are three possible values for this argument:\n    * `default`: Generates functions which use the normal `t`, `tr`, `tf` and `trf` functions, i.e. does not make this\n      feature available. (This is the default value for this argument.)\n    * `custom`: Generates functions which use the new `customTr` and `customTrf` functions.\n    * `both`: Generates two functions for every entry in the JSON file - one using the default translation functions and\n      one using the custom translation functions. Since there are now two functions per JSON entry, we need a unique\n      name for each. This is done by adding a suffix of `Custom` to custom function. For example, if you have a JSON\n      entry called `greetName` then there will be two Elm functions: `greetName` and `greetNameCustom`.\n\nDetails on the command-line arguments are also available by running with the `--help` argument.\n\nBelow is an example of running `elm-i18next-gen` using `npx`, including the arguments:\n\n    npx elm-i18next-gen --source translations/master.json --target src --overwrite\n\n`elm-i18next-gen` can also be integrated into your regular build script. For example say you happen to be using\n[parcel](https://parceljs.org/) to bundle your build, and your `package.json` contains this:\n\n```json\n\"scripts\": {\n\"build\": \"parcel build ...\",\n\"generate-translations\": \"elm-i18next-gen -s translations/master.json -t src -o\"\n```\n\nThe `build` script can be updated to call `generate-translations` as follows:\n\n```json\n\"build\": \"npm run generate-translations && parcel build ...\"\n```\n\n#### Watch Mode\n\nActivating `watch` mode by passing in `--watch` (or `-w`) keeps `elm-i18next-gen` running and watching the source file\nfor changes. Whenever a change occurs, the code will be regenerated. Adding this argument implicitly sets `overwrite` to\ntrue, otherwise it would fail every time after the first code generation.\n\nThis mode is useful when doing a lot of work on translations and wanting changes in the translation file to be made\nimmediately available in the code. It can also give immediate feedback on what changes need to be made in the code if\nthe translation file changes break the existing code. This is shown in the video below. Here\n[parcel](https://parceljs.org/) is serving the app, ensuring the code is compiled as soon as any changes are made to it.\nTherefore when the translation file is updated `elm-i18next-gen` automatically updates the generated code, which causes\nparcel to rebundle the app.\n\n![Code generation demo video](docs/images/code-generation-demo.gif)\n\n### Generated Code\n\n#### Files & Module Structure\n\n`elm-i18next-gen` will generate a file called `Translations.elm` in the specified `target` folder. In it, it will create\na function for every string value in the source JSON. In the source JSON, however, not every key represents a string:\nsome keys are used as parents to group together other string values:\n\n```\n{\n  \"hello\": \"Hello\",             <-- This is a string value\n  \"greetings\": {                <-- This is a grouping of string values\n    \"goodDay\": \"Good day.\",\n    \"greetName\": \"Hi {{name}}\"\n  }\n}\n```\n\nFor every such \"grouping\", an Elm module will be generated. So for the example JSON above, the following structure will\nbe created in the `target` folder:\n\n* `Translations.elm`: contains the `hello` function.\n* `Translations/Greetings.elm`: a `Translations` folder will be created under the `target` folder, and this file will be\n  put there. This file will contain the `goodDay` and `greetName` functions.\n\nModules can be nested as deeply as desired.\n\n#### Module/Function/Parameter Names\n\n`elm-i18next-gen` will generate valid and idiomatic Elm code for the values in the source JSON. Often the generated Elm\nitems (e.g. function names) will directly match the source JSON keys, but in some cases there might be differences. This\nis because the rules and normal usage of JSON and Elm are a bit different. For example, in Elm a function must start\nwith a lower case letter, have no spaces or dashes, and by convention `camelCase` in used. In JSON,\nhowever, `kebab-case`\nperfectly valid, and keys can be lower or upper case.\n\nBecause of this, `elm-i18next-gen` \"sanitises\" the JSON keys before generating the Elm code. For example the JSON key\n`greet-user` will be converted into an Elm function called `greetUser`. This also applies to generated modules and\nparameters.\n\nThis is all fairly intuitive. There is however one case where no completely intuitive solution is obvious: where a JSON\nkey starts with a number. This is not valid in Elm as modules/functions/parameters must start with a letter. Therefore\nin such cases the module/function/parameter will be prefixed with `T` (for modules) or `t` (for functions and\nparameters).\n(`T` is used as shorthand for \"Translation\".)\n\n### Overwriting\n\nAs explained above, the `overwrite` argument defines whether or not the code generation process should overwrite any\nexisting files. If the `overwrite` flag isn't specified the logic is quite simple: the operation will only proceed if\n`Translations.elm` does not exist and the `Translations` folder doesn't exist (or is empty). If `overwrite` is specified\nand there are no submodules, again the logic is simple: `elm-i18next-gen` will simply overwrite that file. However if\n`overwrite` is specified and there are submodules, a complexity can arise...\n\nTaking the example JSON above, we saw that two files were generated: `Translations.elm` and `Translations/Greetings.elm`\n. Now imagine the `greetings` key in the source JSON was renamed to `welcomeMessages`. What should happen here?\nObviously a file called `Translations/WelcomeMessages.elm` should be created, but what should happen to the previously\ngenerated\n`Translations/Greetings.elm`? Similarly, what if the `greetings` section in the JSON was completely removed? Now there's\nno need for the `Translations` folder at all, as there are no submodules to generate. So what should happen with the\npreviously created `Translations` folder?\n\nThe way `elm-i18next-gen` handles this is by deleting any files and folders previously generated in the `Translations`\nfolder, if the newly supplied JSON no longer references them. It also deletes the `Translations` folder itself if it's\nno longer required. Clearly this is potentially dangerous: files are being deleted! If you'd like to use this tool but\ndon't like this (i.e. you'd prefer the files to be put in the trash can / waste bin / recycle bin instead) please log an\nissue.\n\n## Future Enhancements\n\nBelow is a list of possible future enhancements to add to `elm-i18next-gen`. If any of these are important to you,\nplease log an issue and I'll try my best to implement them as soon as I can.\n\n* Allow parameter delimiter to be configured (currently hard-coded to `Curly`).\n* Allow user more control over generated files (e.g. hard-coded default of \"Translations\" as top-level module).\n* Update handling of errors in JSON: provide a list of all errors rather than fail as soon as an error is hit?\n\n## Thanks\n\n* Thanks to [ChristophP](https://github.com/ChristophP), author\n  of [elm-i18next](https://github.com/ChristophP/elm-i18next), for his library, and for taking the time to chat about\n  the idea of code generation for it, and providing great feedback.\n* Thanks to [Dillon Kearns](https://github.com/dillonkearns) for the original inspiration for increased type safety\n  using code generation, from his [elm-graphql](https://github.com/dillonkearns/elm-graphql) library, especially\n  [this talk](https://www.youtube.com/watch?v=memIRXFSNkU) of his.\n","readmeFilename":"README.md","keywords":["elm","internationalization","internationalisation","i18n","i18next","elm-i18next"]}