{"id":21696373,"url":"https://github.com/ryanj93/locale-kit","last_synced_at":"2026-05-10T02:33:13.289Z","repository":{"id":143886788,"uuid":"132368463","full_name":"RyanJ93/locale-kit","owner":"RyanJ93","description":"A simple library that allows to manage language packages and translate texts with Node.js","archived":false,"fork":false,"pushed_at":"2018-05-08T10:41:40.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T14:11:32.410Z","etag":null,"topics":["javascript","javascript-library","localization","node-js","nodejs","translation"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RyanJ93.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":"2018-05-06T19:15:00.000Z","updated_at":"2018-05-08T10:40:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"3a4879ec-5cc3-4032-b515-056e1e5eb1be","html_url":"https://github.com/RyanJ93/locale-kit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanJ93%2Flocale-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanJ93%2Flocale-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanJ93%2Flocale-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanJ93%2Flocale-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RyanJ93","download_url":"https://codeload.github.com/RyanJ93/locale-kit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244635919,"owners_count":20485440,"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":["javascript","javascript-library","localization","node-js","nodejs","translation"],"created_at":"2024-11-25T19:19:38.112Z","updated_at":"2026-05-10T02:33:13.248Z","avatar_url":"https://github.com/RyanJ93.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Locale Kit\n\nLocale Kit is a simple library that allows to manage language packages based on SQLite3 database. It provide also utilities that allow to translate texts as well as detect their language supporting Google and Yandex as service provider. The package is shipped with a CLI utility that allows to create and translate language packages, for more information and documentation check the file called \"cli.md\".\n\n## Installation\n\nBefore installing the package, make sure that the `sqlite3` module is installed, if you are going to install the library through a package manager, the dependence will be installed automatically. To install this package through NPM just run this command:\n\n````bash\nnpm install locale-kit\n````\n\n## Usage: Package\n\nThe class \"Package\" allows to fetch the labels from the language package, before using it you need, of course, to set up the path to the package and the locale to use, the locale must be supported by the package, you can set a locale and allows to the library to switch to a fallback locale based on the language of the given locale code, for example, if you set \"en-US\" as locale but the package doesn't support it, the library will look for any locale matching with \"en\", unless the strict mode is enable, here you are an example:\n\n````javascript\nlet pack = new LocaleKit.Package();\n//path, locale, strict mode\npack.setPackage('path/to/the/package.db', 'en-US', false).then((locale) =\u003e {\n\t//locale is a string containing the locale code selected, if different by the given code, it means that a fallback locale has been picked.\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\nYou can get a list of all the supported locales by using the following method:\n\n````javascript\n//Get all locales.\npack.getSupportedLocales().then((locales) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n//Check for a specific locale support.\n//locale, strict mode\npack.isLocaleSupported('en-US', false).then((value) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\nNow you are able to get the labels, you can use the following method passing an array containing the labels' IDs, the IDs can be represented as numbers or strings, according with the package, the labels will be returned as object having as key the label ID and as value its text, if a label were not found, it will be omitted, here's the example:\n\n````javascript\npack.getLabels([1, 2, 3]).then((labels) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\nOf course you can fetch all the labels from the package using the following method:\n\n````javascript\npack.getAllLabels().then((labels) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\n## Usage: Translator\n\nThe class \"Translator\" allows to translate and detect the language of texts, as of now, it support only Google and Yandex as service provider, in order to use it, you need to get an API key from the provider that you are going to use, by default, Yandex is used because it offers a free plan that allows to translate up to 10000000 chars per month, you can get a free API key from Yandex [here](https://translate.yandex.com/developers), here you are the setup example:\n\n````javascript\nlet translator = new LocaleKit.Translator();\n//token, text format\ntranslator.setupYandex('YOUR API TOKEN HERE', LocaleKit.Translator.HTML);\n````\n\nNow you can translate one or more texts using this method:\n\n````javascript\n//text, target language, original language\ntranslator.translateText(['Ciao mondo!'], 'en', 'it').then((texts) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\nNote that you can omit the original language, in this case it will be automatically detected by the provider. The translated texts will be returned as object having as key the original text and as value the translated one. In a similar way you can detect the language of one or more texts, here you are an example:\n\n````javascript\n//text, target language, original language\ntranslator.detectLanguage(['Ciao mondo!']).then((detections) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\nIt will return an object having as key the original text and as value the code of the language detected. If you need to get a list of all the languages supported by the service provider you can use the following method:\n\n````javascript\ntranslator.getSupportedLanguages('en').then((languages) =\u003e {\n\t//Your stuff here.\n}).catch((ex) =\u003e {\n\t//Handle errors here.\n});\n````\n\nBoth the classes support data caching, you can set up cache using these methods:\n\n````javascript\n//Setup cached for the package.\npack.setCache(true).setCacheHandler(cache);\n//Setup cached for the translator.\ntranslator.setCache(true).setCacheHandler(cache);\n````\n\nData caching is provided by the module \"tiny-cacher\", as you can see in the examples, the variable \"cache\" is an instance of the class \"TinyCacher\" that allows to store data using different options such as Redis, Memcached and file. You can find more information about it on its [repository on GitHub](https://github.com/RyanJ93/tiny-cacher).\n\nIf you like this project and think that is useful don't be scared and feel free to contribute reporting bugs, issues or suggestions or if you feel generous, you can send a donation [here](https://www.enricosola.com/about#donations).\n\nAre you looking for the PHP version? Give a look [here](https://github.com/RyanJ93/php-locale-kit).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanj93%2Flocale-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanj93%2Flocale-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanj93%2Flocale-kit/lists"}