{"id":19777455,"url":"https://github.com/ilib-js/ilib-locale","last_synced_at":"2025-02-28T05:50:35.768Z","repository":{"id":37370891,"uuid":"356149853","full_name":"iLib-js/ilib-locale","owner":"iLib-js","description":"Represent a BCP-47 locale specifier","archived":false,"fork":false,"pushed_at":"2023-12-05T17:44:13.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-11T01:49:49.307Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iLib-js.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-04-09T05:42:11.000Z","updated_at":"2022-05-13T05:24:04.000Z","dependencies_parsed_at":"2024-06-21T13:10:44.421Z","dependency_job_id":"8d3e6413-338b-4af1-b88b-aab1e2cef15b","html_url":"https://github.com/iLib-js/ilib-locale","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-locale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-locale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-locale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-locale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iLib-js","download_url":"https://codeload.github.com/iLib-js/ilib-locale/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241107734,"owners_count":19910975,"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-11-12T05:25:00.477Z","updated_at":"2025-02-28T05:50:35.759Z","avatar_url":"https://github.com/iLib-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003e :warning: **Deprecation Notice** :warning:\n\u003e This repository has been deprecated. Please use the corresponding package from the [iLib-js monorepo](https://github.com/iLib-js/ilib-mono) instead.\n\n# ilib-locale\n\nA BCP-47 locale specifier parser and validator. BCP-47 locale specifiers\nare also known as IETF locale tags.\n\n## Installation\n\n```\nnpm install ilib-locale\n\nor\n\nyarn add ilib-locale\n```\n\n## Parsing Locale Specifiers\n\nHere is how you load ilib-locale:\n\n```javascript\nES2015:\n\nvar Locale = require(\"ilib-locale\");\nvar l = new Locale(\"ja-JP\");\n\nES6:\n\nimport Locale from 'ilib-locale';\nvar l = new Locale(\"ja-JP\");\n```\n\nHere is how you use ilib-locale to parse locale specifiers:\n\n```javascript\nvar l = new Locale(\"zh-Hans-CN\");\nconsole.log(\"Language: \" + l.getLanguage()); // outputs \"zh\"\nconsole.log(\"Script: \" + l.getScript()); // outputs \"Hans\"\nconsole.log(\"Region: \" + l.getRegion()); // outputs \"CN\"\n```\n\nFull documentation: [Locale class](./docs/Locale.md)\n\n## The Current Locale\n\nTo get the default locale of the platform, simply make a new Locale instance\nwithout parameters.\n\n```javascript\nvar locale = new Locale();\n\nconsole.log(\"Current locale is \" + locale.getSpec()); // output \"Current locale is en-US\" in the US\n```\n\nThis module uses `ilib-env` to determine what the current platform is, and looks\nin the appropriate place for the locale specifier. For most modern browsers and\nrecent versions of nodejs, this comes from the `Intl` object, which retrieves\nthe locale from the environment variables or operating system.\n\n## Constructing a Locale\n\nIf you have the locale parts and would like to construct a locale specifier, pass the\nparts to the constructor:\n\n```javascript\nvar language = \"sr\";\nvar script = \"Cyrl\";\nvar region = \"SR\";\nvar variant = \"u-sort-old\";\n\nvar locale = new Locale(language, region, variant, script);\n\nconsole.log(\"Locale spec is \" + locale.getSpec()); // output \"Locale spec is sr-Cyrl-SR-u-sort-old\"\n```\n\n## Validating a Locale\n\nIf you have a string and you would like to validate that it forms a valid BCP-47 tag,\nyou can use the `isValid` method to do that:\n\n```javascript\nvar l = new Locale(\"mn-XM\");\n\nconsole.log(\"Locale is valid: \" + l.isValid());\n// output \"Locale is valid: false\" because XM is not a valid region code\n```\n\nIn order for a locale spec to be valid, each of its parts needs to conform to the\ncodes in the ISO standard that governs that part:\n\n- Language. Language codes must be one of the [two-](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) or \n  [three-](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) lower-case letter codes from the\n  [ISO 639](https://en.wikipedia.org/wiki/ISO_639) standard.\n- Script. Script codes must be one of the four letter codes from the\n  [ISO 15924](https://en.wikipedia.org/wiki/ISO_15924) standard.\n- Region. Region codes must be one of the two upper-case letter codes from the\n  [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166) alpha-2\n  standard or a 3 digit code from the [UN M49](https://en.wikipedia.org/wiki/UN_M49)\n  standard or the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_numeric) numeric-3 standard.\n\n\n# License\n\nCopyright © 2021-2023, JEDLSoft\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n# Release Notes\n\n### v1.2.3\n\n* Convert all unit tests from nodeunit to jest\n* added ability to run tests on browsers via karma\n\n### v1.2.2\n\n* This module is now a hybrid ESM/CommonJS package that works under node\n  or webpack\n\n### v1.2.1\n\n* Removed dependency on polyfills that are not needed, which should make this\n  easier to depend upon.\n\n### v1.2.0\n\n* Now ships both the ES6 modules in the src directory and the commonjs code\n  (transpiled with babel) in the lib directory. Callers can choose which one\n  they would like to use.\n\n### v1.1.1\n\n* Update dependencies and target the right node \u0026 browser versions with babel\n\n### v1.1.0\n\n- added the ability to parse locale specs that contain underscores\n  instead of dashes. Some locale specs for Java properties file names\n  or in some gnu gettext libraries are specified with underscores.\n  (ie. \"zh_Hans_CN\" === \"zh-Hans-CN\" now)\n- updated dependencies\n\n### v1.0.2\n\n- fixed some incorrect unit tests\n\n### v1.0.1\n\n- do not put the module name into the package.json, because it screws\nup the import of ilib-locale in other apps that use webpack\n- added API documentation\n- added new way of doing web testing using a webpacked version of the tests\n\n### v1.0.0\n\n- Code taken from ilib 14.7.0 and converts to an ES6 module.\n- Use babel to transpile it back to ES2015 so it can be used in either ES215 or \n  ES6 code\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filib-js%2Filib-locale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filib-js%2Filib-locale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filib-js%2Filib-locale/lists"}