{"id":28466586,"url":"https://github.com/locize/locizer","last_synced_at":"2025-07-06T00:35:33.822Z","repository":{"id":58223158,"uuid":"75287977","full_name":"locize/locizer","owner":"locize","description":"locize connector to the backend for your browser","archived":false,"fork":false,"pushed_at":"2025-01-23T09:17:41.000Z","size":243,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-30T08:15:13.939Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/locize.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-12-01T11:53:18.000Z","updated_at":"2025-06-28T20:27:56.000Z","dependencies_parsed_at":"2024-06-21T04:18:10.407Z","dependency_job_id":"cd553cfd-3400-40db-be3b-fd861b957842","html_url":"https://github.com/locize/locizer","commit_stats":{"total_commits":88,"total_committers":3,"mean_commits":"29.333333333333332","dds":0.2272727272727273,"last_synced_commit":"7b52b06da07362a801643af50e69e5d3615b8ca9"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/locize/locizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locize%2Flocizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locize%2Flocizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locize%2Flocizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locize%2Flocizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/locize","download_url":"https://codeload.github.com/locize/locizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locize%2Flocizer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263832177,"owners_count":23517347,"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-06-07T07:04:51.045Z","updated_at":"2025-07-06T00:35:33.806Z","avatar_url":"https://github.com/locize.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Travis](https://img.shields.io/travis/locize/locizer/master.svg?style=flat-square)](https://travis-ci.org/locize/locizer)\n[![npm version](https://img.shields.io/npm/v/locizer.svg?style=flat-square)](https://www.npmjs.com/package/locizer)\n\n# locizer.js\n\nlocizer.js is lightweight client to access data from your locize project and use that inside your application (eg. passing that to polyglot, formatjs).\n\n# Getting started\n\nSource can be loaded via [npm](https://www.npmjs.com/package/locizer) or [downloaded](https://github.com/locize/locizer/blob/master/locizer.min.js) from this repo.\n\nOr load it from the offical npm cdn:\n\n[https://unpkg.com/locizer[@version]/locizer[.min].js](https://unpkg.com/locizer/locizer.min.js)\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cscript src=\"https://unpkg.com/locizer/locizer.min.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n      locizer\n        .init({\n          fallbackLng: \"en\",\n          referenceLng: \"en\",\n          projectId: \"[your project id]\"\n        })\n        .load(\"translation\", function(err, translations, lng) {\n          // feed the translations to formatjs, polyglot,...\n        });\n    \u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\u003c/body\u003e\n\u003c/html\u003e\n```\n\n# Init options\n\n**IMPORTANT** make sure you do not add your apiKey in the production build to avoid misuse by strangers\n\n```js\n{\n  lng: 'en', // optional if set we won't detect language of user\n  fallbackLng: 'en',\n  referenceLng: 'en',\n\n  loadIfTranslatedOver: 0.1, // default 1 - we only load lngs that are fully translated, lower this value to load files from languages that are just partially translated\n\n  projectId: 'c8038fbe-7be8-4f96-9692-943b3333185b',\n  apiKey: '27e9ecff-8926-43b0-80fd-e683abe49297', // only needed if you want to add new keys via locizer - remove on production!\n  version: 'latest', // version to load from locize\n  private: false, // set true if using locize private publish\n\n  // hostnames that are allowed to send last used data\n  // please keep those to your local system, staging, test servers (not production)\n  allowedHosts: ['localhost'],\n  // hostnames that are allowed to add, update keys\n  // please keep those to your local system, staging, test servers (not production)\n  allowedAddOrUpdateHosts: ['localhost'],\n\n  // language detection options:\n\n  // order and from where user language should be detected\n  order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],\n\n  // keys or params to lookup language from\n  lookupQuerystring: 'lng',\n  lookupCookie: 'i18next',\n  lookupLocalStorage: 'i18nextLng',\n\n  // cache user language on\n  caches: ['localStorage', 'cookie'],\n\n  // optional expire and domain for set cookie\n  cookieMinutes: 10,\n  cookieDomain: 'myDomain',\n\n  // optional htmlTag with lang attribute, the default is:\n  htmlTag: document.documentElement\n}\n```\n\n# Example usage\n\n## vue-i18n (Vue v3)\n\nThe full example can be found [here](https://github.com/locize/locizer/tree/master/example/vue).\n\n```js\nimport { createI18n } from 'vue-i18n'\nimport locizer from 'locizer'\n\nlocizer.init({\n  projectId: '1fb2c780-f038-4ffe-b988-5d9fe2e3ba2d'\n});\n\nexport const i18n = createI18n({\n  locale: locizer.lng, // set locale\n  fallbackLocale: 'en' // set fallback locale\n  // If you need to specify other options, you can set other options\n  // ...\n});\n\n// called from within setup hook in App.vue\nexport const loadMessagesPromise = new Promise((resolve, reject) =\u003e {\n  locizer.loadAll('messages', (err, messages) =\u003e {\n    if (err) return reject(err);\n    Object.keys(messages).forEach((l) =\u003e {\n      i18n.global.setLocaleMessage(l, messages[l])\n    });\n    resolve(messages);\n  });\n})\n\n```\n\n# API\n\n## init\n\n```js\nlocizer.init(options);\n```\n\n## getLanguage\n\n```js\n// gives the language provided in options or detected from user compared to languages existing in your project (see also init option: loadIfTranslatedOver)\nlocizer.getLanguage((err, lng) =\u003e {));\n\n// if you want the language detected but unfiltered against what your project provided\nvar loc = locizer.detector.detect();\n```\n\n## getLanguages\n\n```js\n// gives you all languages supported in your project\nlocizer.getLanguages((err, lngs) =\u003e {));\n\n// something like:\n{\n  \"en\": {\n    \"name\": \"English\",\n    \"nativeName\": \"English\",\n    \"translated\": {\n      \"latest\": 1\n    }\n  },\n  \"de\": {\n    \"name\": \"German\",\n    \"nativeName\": \"Deutsch\",\n    \"translated\": {\n      \"latest\": 0.19999999999999998\n    }\n  }\n}\n```\n\n## load\n\n```js\n// load a namespace from locize in the lng provided in options or detected from user\nlocizer.load(\"namespace\", (err, res) =\u003e {});\n\n// load in different lng\nlocizer.load(\"namespace\", \"de\", (err, res) =\u003e {});\n```\n\n## loadAll\n\n```js\n// load a namespace from locize in all languages\nlocizer.loadAll(\"namespace\", (err, res) =\u003e {\n  // res:\n  // {\n  //   en: {\n  //     hello: \"hello world\"\n  //   },\n  //   de: {\n  //     hello: \"hallo welt\"\n  //   }\n  // }\n});\n```\n\n## add\n\n```js\n// add a new key\nlocizer.add(\"myNamespace\", \"myKey\", \"myValue\", \"context information\");\n```\n\n## update\n\n```js\n// add a new key\nlocizer.update(\"myNamespace\", \"myKey\", \"myValue\", \"context information\");\n```\n\n## setting last used info\n\n```js\n// add a new key\nlocizer.used(\"myNamespace\", \"myKey\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocize%2Flocizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocize%2Flocizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocize%2Flocizer/lists"}