{"id":13671084,"url":"https://github.com/montzkie18/react-localoader","last_synced_at":"2025-04-27T14:33:04.029Z","repository":{"id":57334114,"uuid":"134869707","full_name":"montzkie18/react-localoader","owner":"montzkie18","description":"Automatically localize all texts in your React project during Webpack builds","archived":false,"fork":false,"pushed_at":"2018-06-14T07:29:07.000Z","size":88,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T13:09:32.264Z","etag":null,"topics":["ast","i18n","internationalization","localization","react","react-localoader","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":null,"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/montzkie18.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}},"created_at":"2018-05-25T14:52:53.000Z","updated_at":"2019-09-27T04:44:36.000Z","dependencies_parsed_at":"2022-08-31T02:01:15.315Z","dependency_job_id":null,"html_url":"https://github.com/montzkie18/react-localoader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montzkie18%2Freact-localoader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montzkie18%2Freact-localoader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montzkie18%2Freact-localoader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montzkie18%2Freact-localoader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/montzkie18","download_url":"https://codeload.github.com/montzkie18/react-localoader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250850334,"owners_count":21497491,"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":["ast","i18n","internationalization","localization","react","react-localoader","webpack","webpack-loader"],"created_at":"2024-08-02T09:00:58.473Z","updated_at":"2025-04-27T14:33:03.613Z","avatar_url":"https://github.com/montzkie18.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# React Localization Loader\n\n[![npm version](https://badge.fury.io/js/react-localoader.svg)](https://badge.fury.io/js/react-localoader) [![Build Status](https://travis-ci.org/montzkie18/react-localoader.svg?branch=master)](https://travis-ci.org/montzkie18/react-localoader)\n\nAutomatically converts all your React components from this:\n```javascript\nimport React from 'react';\nimport Tooltip from './Tooltip';\n\nconst CustomComponent = (props) =\u003e (\n  \u003cdiv\u003e\n    Welcome {props.username}, click \u003ca href=\"http://link.com\"\u003ehere\u003c/a\u003e\n    \u003cTooltip text=\"Hi there\"/\u003e\n  \u003c/div\u003e\n);\n```\n\nTo this:\n```javascript\nimport i18n from 'react-localoader/lib/i18n';\nimport Localize from 'react-localoader/lib/components/Localize';\nimport React from 'react';\nimport Tooltip from './Tooltip';\n\nconst CustomComponent = (props) =\u003e (\n  \u003cdiv\u003e\n    \u003cLocalize elements={[\u003ca href=\"http://link.com\"\u003e$1\u003c/a\u003e]}\n      expressions={{\"props-username\": props.username}}\n    \u003eWelcome %[props-username], click *here*\u003c/Localize\u003e \n    \u003cTooltip text={i18n.t(\"Hi there\")}/\u003e\n  \u003c/div\u003e\n);\n```\n\n## Usage\n\n```\nnpm install --save react-localoader\n```\n\nIn your webpack config, just add a new loader for JS/JSX files like this:\n```\nvar baseConfig = {\n  // ...\n  module: {\n    rules: [{\n        test: /\\.(js|jsx)$/,\n        loader: 'react-localoader'\n    }]\n  }\n};\n```\n\n## Config File\n\nAll configurations are loaded from `.i18nrc` JSON file located at the root of your project folder. The JSON file looks like something below:\n\n```\n{\n  \"basePath\": \".\",\n  \"srcFolders\": [\"src\"],\n  \"defaultLocale\": \"en\",\n  \"exportPath\": \"./public/locale\",\n  \"attributeNames\": [\"text\", \"placeholder\", \"label\", \"content\"],\n  \"attributeIgnores\": [\"textSpacing\", \"labelPosition\"]\n}\n```\n\n## Config Options\n##### basePath\nRoot folder to search for source files to localize.\n\n##### srcFolders\nFolders inside the basePath where all your JS/JSX files are located. This is used by the CLI commands and not by the webpack loader. Supports glob patterns.\n\n##### defaultLocale\nDefines which locale your current React components are written so they can be exported to `${exportPath}/${defaultLocale}.json`\n\n##### exportPath\nFolder where all exported `${locale}.json` data will be saved.\n\n##### attributeNames\nRegex patterns of JSX attributes you want to localize. Remember that this is always treated as a pattern so `label` will always include both `label` and `labelPosition`. You must include `labelPosition` to `attributeIgnores` if you do not want it to be localized.\n\n##### attributeIgnores\nList of specific attribute names you want excluded from localization.\n\n## CLI\n\nYou can use the following commands to manage your locale data.\n\n##### \u003e react-localoader export\n\nApplies localization to all your source code inside your defined `srcFolders`. It then extracts all the children of `\u003cLocalize\u003e` tag and first param of `i18n.t()` call. All this strings are compiled and saved to `${exportPath}${defaultLocal}.json` in the following format:\n```json\n[\n  {\n    \"string_keyhash\": {\n      \"description\": \"./path/to/component/this/was/extracted/from\",\n      \"text\": \"Text we need to localize\"\n    }\n  },\n  ...\n]\n```\n\n## Credits\n\nThis project was inspired by Jon Jensen's work [here](https://github.com/jenseng/react-i18nliner)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmontzkie18%2Freact-localoader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmontzkie18%2Freact-localoader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmontzkie18%2Freact-localoader/lists"}