{"id":25602867,"url":"https://github.com/dacampsss/simplelocaleloader","last_synced_at":"2025-11-11T09:30:50.496Z","repository":{"id":178684627,"uuid":"414472241","full_name":"dacampsss/SimpleLocaleLoader","owner":"dacampsss","description":"A really minimal and simple ES6 module that uses eval() for basic and flexible localization or interpolation.","archived":false,"fork":false,"pushed_at":"2021-10-08T07:37:05.000Z","size":863,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-30T04:28:17.549Z","etag":null,"topics":["es6","i18n","interpolation","javascript","localization","minimal","module","oop","tiny"],"latest_commit_sha":null,"homepage":"https://daltroaugusto.github.io/SimpleLocaleLoader/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dacampsss.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":"2021-10-07T05:28:09.000Z","updated_at":"2021-10-07T08:11:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"308a9d37-4a33-40dd-a0e5-a0a85e468440","html_url":"https://github.com/dacampsss/SimpleLocaleLoader","commit_stats":null,"previous_names":["daltroaugusto/simplelocaleloader","dacampsss/simplelocaleloader"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dacampsss%2FSimpleLocaleLoader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dacampsss%2FSimpleLocaleLoader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dacampsss%2FSimpleLocaleLoader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dacampsss%2FSimpleLocaleLoader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dacampsss","download_url":"https://codeload.github.com/dacampsss/SimpleLocaleLoader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240056120,"owners_count":19741080,"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":["es6","i18n","interpolation","javascript","localization","minimal","module","oop","tiny"],"created_at":"2025-02-21T17:24:20.229Z","updated_at":"2025-11-11T09:30:50.490Z","avatar_url":"https://github.com/dacampsss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleLocaleLoader\n\nA really minimal and simple ES6 module that uses eval() for basic and flexible localization or interpolation.\n\n# Usage example\n\nAs this one is projected for really tiny, small projects (despite being really flexible, as opts to use eval), its usage is really simple. Examples below pressupose to be executed inside `\u003cscript type=\"module\"\u003e` blocks or with your preferred bundler.\n```html\n\u003c!-- index.html --\u003e\n\u003chead\u003e\n    \u003ctitle string=\"index.title\"\u003e\u003c/title\u003e\n    \u003cscript type=\"module\" src=\"index.script.mjs\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cspan string=\"index.theText[0]\"\u003e\u003c/span\u003e\n    \u003cspan string=\"index.theText[1]\"\u003e\u003c/span\u003e\n\u003c/body\u003e\n```\n\n```json\n/* locales/en.json */\n{\n    \"index\": {\n        \"index\": \"title of this page\",\n        \"theText\": [\"some text here\", \"more text here\"]\n    }\n}\n```\n\n```json\n/* locales/pt.json */\n{\n    \"index\": {\n        \"title\": \"título desta página\",\n        \"theText\": [\"algum texto aqui\", \"mais texto aqui\"]\n    }\n}\n```\n\n```json\n/* locales/index.json */\n[\n    \"pt\", \"en\"\n]\n```\nIn the file above, you put all your available locale codes inside this one array.\n\n```javascript\n// index.script.mjs\nimport LocaleLoader from 'assets/localeloader.js';\nconst locales = new LocaleLoader('locales/index.json');\n\nlocales.initialize()\n.then(() =\u003e {\n    doSomething();\n});\n```\nThis one is a simple example of usage. `initialize` method, by default, will load the appropriated locale strings and fulfill document elements containing `string` or `placeholderstring` attributes with valid string keys. But let's say we don't want the default `en` fallbackLocale, or even to inject strings at startup...\n\n```javascript\nlocales.initialize()\n.then(() =\u003e {\n    // do nothing\n}, false, 'zh');\n```\n\nAs we are explictly using `eval()` here, possibilities are broad. Risks too, so: **be aware, never EVER involve any user-inputted data within string tags**. Now let's check out more examples and features of this tiny lib...\n\n## Placeholder injection\n```html\n\u003c!-- index.html:some-line --\u003e\n\u003cinput type=\"password\" placeholderstring=\"index.inputPasswd\" /\u003e\n```\n\n## *localesloaded* custom event\nThis event happens after Object.localizeDocument() is completed, i.e. all possible strings are checked and fulfilled.\n```javascript\n/* index.script.mjs */\nwindow.addEventListener('localesloaded', () =\u003e {\n    const $ = (el) =\u003e document.querySelector(el);\n    $('.loadingWrapper').className += ' loaded';\n});\n```\n\n## Get a string\nLet's say you just need to get a single string?\n```javascript\nconst thisString = locales.getString('index.alert');\nwindow.alert(thisString);\n```\n\nImportant to notice that this one will work **only** if your locale strings were already loaded by your SimpleLocaleLoader object, i.e. on (after) `window.localesloaded` event or in a moment you're sure `initialize` promise is fulfilled.\n\n### Get an array or object\nBy the same logic, you can get an entire array or object from your json's locale file.\n```javascript\nfor(const item of locales.getString('index')) {\n    doSomething(item);\n}\n```\n\n# License\n\n```\n\n  Copyright 2021 Daltro A. Campanher de Souza\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n      http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdacampsss%2Fsimplelocaleloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdacampsss%2Fsimplelocaleloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdacampsss%2Fsimplelocaleloader/lists"}