{"id":20350022,"url":"https://github.com/webbestmaster/react-localization-library","last_synced_at":"2025-04-12T01:30:34.481Z","repository":{"id":47779500,"uuid":"392766290","full_name":"webbestmaster/react-localization-library","owner":"webbestmaster","description":"React localization hooks and components","archived":false,"fork":false,"pushed_at":"2024-09-24T22:08:09.000Z","size":325,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T21:11:49.818Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/webbestmaster.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-08-04T16:58:32.000Z","updated_at":"2024-09-24T22:08:13.000Z","dependencies_parsed_at":"2024-07-06T16:10:23.189Z","dependency_job_id":null,"html_url":"https://github.com/webbestmaster/react-localization-library","commit_stats":{"total_commits":75,"total_committers":3,"mean_commits":25.0,"dds":"0.41333333333333333","last_synced_commit":"3d8c6f1058f378e206c6c9778eb8e2f7e745fd68"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Freact-localization-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Freact-localization-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Freact-localization-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Freact-localization-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webbestmaster","download_url":"https://codeload.github.com/webbestmaster/react-localization-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248504181,"owners_count":21115132,"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-14T22:28:36.397Z","updated_at":"2025-04-12T01:30:34.462Z","avatar_url":"https://github.com/webbestmaster.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Localization Library\n\n[![GitHub license](https://img.shields.io/npm/l/react-localization-library)](https://github.com/webbestmaster/react-localization-library/blob/master/license)\n[![codecov](https://codecov.io/gh/webbestmaster/react-localization-library/branch/master/graph/badge.svg)](https://codecov.io/gh/webbestmaster/react-localization-library)\n[![npm version](https://img.shields.io/npm/v/react-localization-library.svg)](https://www.npmjs.com/package/react-localization-library)\n[![Known Vulnerabilities](https://snyk.io/test/github/webbestmaster/react-localization-library/badge.svg)](https://snyk.io/test/github/webbestmaster/react-localization-library)\n[![Dependency count](https://badgen.net/bundlephobia/dependency-count/react-localization-library)](https://libraries.io/npm/react-localization-library)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-localization-library)](https://bundlephobia.com/package/react-localization-library)\n[![nodejs version](https://img.shields.io/node/v/react-localization-library)](https://nodejs.org/en/docs)\n[![Github CI](https://github.com/webbestmaster/react-localization-library/actions/workflows/github-ci.yml/badge.svg)](https://github.com/webbestmaster/react-localization-library/actions/workflows/github-ci.yml)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/webbestmaster/react-localization-library/github-ci.yml)](https://github.com/webbestmaster/react-localization-library/actions/workflows/github-ci.yml)\n[![Type definitions](https://img.shields.io/npm/types/react-localization-library)](https://www.typescriptlang.org)\n[![Website](https://img.shields.io/website?url=https://github.com/webbestmaster/react-localization-library)](https://github.com/webbestmaster/react-localization-library)\n[![CodeFactor](https://www.codefactor.io/repository/github/webbestmaster/react-localization-library/badge)](https://www.codefactor.io/repository/github/webbestmaster/react-localization-library)\n[![Package Quality](https://packagequality.com/shield/react-localization-library.svg)](https://packagequality.com/#?package=react-localization-library)\n[![GitHub stars](https://img.shields.io/github/stars/webbestmaster/react-localization-library?style=social)](https://github.com/webbestmaster/react-localization-library)\n\n\u003c!--\n[![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/webbestmaster/react-localization-library)](https://libraries.io/npm/react-localization-library)\n--\u003e\n\nReact localization hooks and components.\n\n## Install\n\n```bash\nnpm i react-localization-library\n```\n\n## Usage\n```typescript jsx\nimport {createLocalization, type LocalizationConfigType, type LocalizationStateType} from 'react-localization-library';\n\nconst enUs = {\n    DIFFERENT_VARIABLES: 'Hello, {one}!',\n    FRIEND: 'friend',\n    HELLO: 'Hello',\n    HELLO_SMTH: 'Hello, {smth}!',\n    // KEY_ONLY_EU_US: 'Hello, en-US!', // throw error when using\n};\n\n/*\nconst ruRu = {\n    DIFFERENT_VARIABLES: 'Hello, {two}!',\n    FRIEND: 'друг',\n    HELLO: 'Привет',\n    HELLO_SMTH: 'Привет, {smth}!',\n    KEY_ONLY_RU_RU: 'Hello, ru-RU!', // throw error when using\n};\n*/\n\ntype LocaleNameType = 'en-US' | 'ru-RU';\ntype LocaleKeysType = keyof typeof enUs; // \u0026 keyof typeof ruRu;\n\nconst localizationConfig: LocalizationConfigType\u003cLocaleKeysType, LocaleNameType\u003e = {\n    defaultLocaleName: 'en-US',\n    localization: {\n        'en-US': enUs,\n        'ru-RU': async () =\u003e {\n            const {ruRu} = await import('./ru-ru');\n\n            return ruRu;\n        },\n    },\n    onUseEffect: (data: LocalizationStateType\u003cLocaleNameType\u003e) =\u003e {\n        const {localeName: newLocaleName} = data;\n\n        console.log('new locale name', newLocaleName);\n    },\n};\n\nconst {\n    LocalizationProvider, // provider, required as wrapper\n    useLocale, // hook\n    Locale, // helpful component\n} = createLocalization\u003cLocaleKeysType, LocaleNameType\u003e(localizationConfig);\n\nfunction ExampleComponent(): JSX.Element {\n    const {\n        localeName, // LocaleNameType, in this case: 'en-US' | 'ru-RU'\n        isFetchingLocaleData, // boolean\n        getLocalizedString, // (stringKey: LocaleKeysType, valueMap?: Record\u003cstring, string\u003e) =\u003e string;\n        setLocaleName, // (localeName: LocaleNameType) =\u003e void\n    } = useLocale();\n\n    return (\n        \u003c\u003e\n            \u003ch1\u003eCurrent locale: {localeName}\u003c/h1\u003e\n            \u003ch2\u003eLocalization data is fetching: {isFetchingLocaleData ? 'Yes' : 'No'}\u003c/h2\u003e\n\n            \u003cbutton onClick={() =\u003e setLocaleName('en-US')} type=\"button\"\u003e\n                use en-US\n            \u003c/button\u003e\n            \u003cbutton onClick={() =\u003e setLocaleName('ru-RU')} type=\"button\"\u003e\n                use ru-RU\n            \u003c/button\u003e\n\n            \u003cp\u003eExample 1\u003c/p\u003e\n\n            {getLocalizedString('FRIEND')}\n            \u003cbr /\u003e\n            {getLocalizedString('HELLO_SMTH', {smth: 'type string'})}\n            \u003cbr /\u003e\n            {getLocalizedString('DIFFERENT_VARIABLES', {one: 'word 1', two: 'word 2'})}\n\n            \u003cp\u003eExample 2\u003c/p\u003e\n\n            \u003cLocale stringKey=\"FRIEND\" /\u003e\n            \u003cbr /\u003e\n            \u003cLocale stringKey=\"HELLO_SMTH\" valueMap={{smth: \u003cLocale stringKey=\"FRIEND\" /\u003e}} /\u003e\n            \u003cbr /\u003e\n            \u003cLocale stringKey=\"DIFFERENT_VARIABLES\" valueMap={{one: 'word 1', two: 'word 2'}} /\u003e\n        \u003c/\u003e\n    );\n}\n\nexport function ExampleApp(): JSX.Element {\n    return (\n        \u003cLocalizationProvider\n            forcedLocaleName=\"ru-RU\" // forcedLocaleName optional and will rewrite a defaultLocaleName from config\n        \u003e\n            \u003cExampleComponent /\u003e\n        \u003c/LocalizationProvider\u003e\n    );\n}\n```\n\n## License\n\nSee [license](license).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebbestmaster%2Freact-localization-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebbestmaster%2Freact-localization-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebbestmaster%2Freact-localization-library/lists"}