{"id":15379289,"url":"https://github.com/andreasbm/an-translate","last_synced_at":"2026-01-12T13:30:18.516Z","repository":{"id":94647734,"uuid":"111476081","full_name":"andreasbm/an-translate","owner":"andreasbm","description":"A showcase of how custom attributes can be used for translations.","archived":false,"fork":false,"pushed_at":"2017-12-07T20:31:49.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-30T00:28:32.368Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreasbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-11-20T23:59:17.000Z","updated_at":"2019-02-27T23:46:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"c87a37bb-a787-4f6f-bba7-61c03c7b0f53","html_url":"https://github.com/andreasbm/an-translate","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"ee2e3f4acd01cc63a00e785658520f46af2c69f6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasbm%2Fan-translate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasbm%2Fan-translate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasbm%2Fan-translate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasbm%2Fan-translate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreasbm","download_url":"https://codeload.github.com/andreasbm/an-translate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239748337,"owners_count":19690243,"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":"2024-10-01T14:18:43.588Z","updated_at":"2025-02-19T23:19:51.501Z","avatar_url":"https://github.com/andreasbm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# an-translate\n\nThis is a cool showcase of how web components and custom attributes can be used for translations.\n\nDemo: [https://andreasbm.github.io/an-translate/](https://andreasbm.github.io/an-translate/)\n\n## 👍 Step 1 - Create a JSON file with your strings\n```json\n{\n\t\"title\": \"Hello World!\",\n\t\"subtitle\": \"This is a cool showcase of how web components and custom attributes can be used for translations.\",\n\t\"language\": {\n\t\t\"danish\": \"Danish\",\n\t\t\"english\": \"English\"\n\t}\n}\n\n```\n\n## 👊 Step 2 - Load the translation strings through an-translate-controller\n\nCan either be in markup.\n\n```html\n\u003can-translate-controller src=\"strings/en.json\"\u003e\u003c/an-translate-controller\u003e\n```\n\nOr in Javascript.\n\n```js\nconst translate = document.querySelector(\"an-translate-controller\");\ntranslate.src = \"strings/en.json\";\n```\n\n## 💪 Step 3 - Use the an-translate attribute to get the translated strings\n\n```html\n\u003ch1 an-translate=\"title\"\u003e\u003c/h1\u003e\n\u003ch1 an-translate=\"language.english\"\u003e\u003c/h1\u003e\n```\n\nWill result in:\n\n```\nHello World!\nEnglish\n```\n\nThe strings will of course update themselves whenever you change the attribute value or the strings source.\n\nYou can also get the translations, using the get method on the AnTranslateController.\n\n```js\ntranslate.get(\"title\", { name: \"World\" })); // Hello World!\n```\n\n## 🤘 Step 4 - Use placeholders and fill them out on run time\n\nIf you want to use placeholders, that is possible. Use the double curly brackets syntax {{ key }} in your strings (the spaces are optional) and interpolate them in the attribute value using the \":\" character followed by a key-value pairs object. Like this:\n```json\n{\n\t\"title\": \"{{ greeting }} {{ name }}!\",\n}\n\n```\n\n```html\n\u003ch1 an-translate='title:{ \"greeting\": \"Hello\", \"name\": \"World\"}'\u003e\u003c/h1\u003e\n\u003ch1 an-translate='title:{ \"greeting\": \"Good morning\", \"name\": \"Andreas\"}'\u003e\u003c/h1\u003e\n```\n\nWill result in:\n\n```\nHello World!\nGood morning Andreas!\n```\n\n# 👏 Licence\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreasbm%2Fan-translate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreasbm%2Fan-translate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreasbm%2Fan-translate/lists"}