{"id":16520600,"url":"https://github.com/christophp/elm-i18next","last_synced_at":"2025-03-16T19:31:03.451Z","repository":{"id":42224152,"uuid":"90202635","full_name":"ChristophP/elm-i18next","owner":"ChristophP","description":"https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest","archived":false,"fork":false,"pushed_at":"2023-03-04T02:58:21.000Z","size":270,"stargazers_count":66,"open_issues_count":7,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-12T16:51:34.581Z","etag":null,"topics":["elm","i18n","i18next","json","translations"],"latest_commit_sha":null,"homepage":"","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChristophP.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":"2017-05-03T23:42:30.000Z","updated_at":"2023-07-25T14:08:52.000Z","dependencies_parsed_at":"2024-06-21T07:27:34.267Z","dependency_job_id":"94dc9740-0450-4fd5-b554-6fc5444fdf75","html_url":"https://github.com/ChristophP/elm-i18next","commit_stats":{"total_commits":107,"total_committers":8,"mean_commits":13.375,"dds":0.2990654205607477,"last_synced_commit":"e38aba490aaccd25fed55390f9914f4c7fce3b53"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristophP%2Felm-i18next","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristophP%2Felm-i18next/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristophP%2Felm-i18next/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristophP%2Felm-i18next/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChristophP","download_url":"https://codeload.github.com/ChristophP/elm-i18next/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221667192,"owners_count":16860569,"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":["elm","i18n","i18next","json","translations"],"created_at":"2024-10-11T16:51:49.474Z","updated_at":"2024-10-27T11:09:05.142Z","avatar_url":"https://github.com/ChristophP.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elm i18next - Load and use JSON translations files at runtime\n\nFunctions for working with dynamically loaded translations in Elm.\nPRs and suggestions welcome.\n\n## Simple Example\n\n```elm install ChristophP/elm-i18next```\n\nThen use the module in your app like this.\n\nIn JS do:\n```js\n// translations is a JSON string or JS object\nElm.Main.init({ flags: translations });\n```\n\nThen in elm, you use them in the `init` function of your app:\n\n```elm\nimport Html exposing (Html)\nimport I18Next exposing\n      ( t\n      , tr\n      , Translations\n      , Delims(..)\n      , translationsDecoder\n      )\nimport Json.Encode\nimport Json.Decode\n\ntype alias Model = {\n  translations: Translations\n}\n\ntype Msg = ..\n\ninit : Json.Encode.Value -\u003e (Model, Cmd msg)\ninit flags =\n    case Json.Decode.decodeValue translationsDecoder flags of\n        Ok translations -\u003e\n            ( Model translations, Cmd.none )\n\n        Err err -\u003e\n            -- handle the error\n\n{- Imagine your translations file looks like this:\n  {\n    \"hello\": \"Hallo\",\n    \"greetings\": {\n      \"goodDay\": \"Good day.\",\n      \"greetName\": \"Hi {{name}}\"\n    }\n  }\n-}\n\nview : Model -\u003e Html Msg\nview model =\n    div []\n        [ div [] [ text (t model.translations \"hello\") ] -- \"Hallo\"\n        , div [] [ text (t model.translations \"greetings.goodDay\") ] -- \"Good day.\"\n        , div [] [ text (t model.translations \"nonExistingKey\") ] -- \"nonExistingKey\"\n        , div [] [ text (tr model.translations Curly \"greetings.greetName\" [(\"name\", \"Peter\")]) ] -- \"Hi Peter\"\n        ]\n```\n\nCheck out more complete examples [here](https://github.com/ChristophP/elm-i18next/tree/master/examples)\n\n## Fetching Translations\n\nIf you can't pass the translations as flags but want to fetch them from Elm code\ninstead do the same as in the simple example but apply the decoder to the Http call.\n\n## Advanced Stuff: Placeholders and fallback languages\n\nHere are some supported features for advanced use cases:\n- Support for string placeholders\n- Support for non-string placeholders such as `Html`\n- Fallback languages\n\nCheck the officialj\n[docs](http://package.elm-lang.org/packages/ChristophP/elm-i18next/latest/I18Next)\nfor usage examples.\n\n## Adding Type safety\n\nIf you want to add type safety for your translations, try this awesome generator\ncalled [`elm-i18next-gen`](https://github.com/yonigibbs/elm-i18next-gen).\nIt combines the dynamic nature of loading JSON files with the power of Elm's type system.\n\n## Background\n\nDealing with Translations in Elm has always come with some hoops to jump\nthrough. Existing solutions include tricks like passing already translated\nstrings into the elm app as flags or generating Translation modules as a\npre-build step like\n[here](https://github.com/ChristophP/elm-i18n-module-generator) or\n[here](https://github.com/iosphere/elm-i18n).\n\nInspired by the `i18next` client in from the JS world. This elm module\nallows you to load JSON translation files via HTTP and then use the\ndata in your Elm app. This should allow for a easier-to-use\ninternationalization as existing solutions.\n\n\n## Contributing\n\nIf you want to contribute, PRs are highly welcome. If you need a feature or want\nto share ideas, please open an issue or catch me in the elm slack channel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophp%2Felm-i18next","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristophp%2Felm-i18next","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophp%2Felm-i18next/lists"}