forked from lokalise/i18n-ally
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding new
scopeRangeRegex
config to the custom framework (lo…
…kalise#926) * Feat: Adding new namespaceMatchRegex config to the custom framework options * Empty commit to trigger CI --------- Co-authored-by: Amanda Ranard <amanda.ranard@thetradedesk.com> Co-authored-by: Alex Terehov <terales@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
205 additions
and
2 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
examples/by-features/custom-scope-range/.vscode/i18n-ally-custom-framework.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
languageIds: | ||
- javascript | ||
- typescript | ||
- javascriptreact | ||
- typescriptreact | ||
scopeRangeRegex: "customScopeRangeFn\\(\\s*\\[?\\s*['\"`](.*?)['\"`]" | ||
monopoly: false |
7 changes: 7 additions & 0 deletions
7
examples/by-features/custom-scope-range/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"i18n-ally.localesPaths": "public/locales", | ||
"i18n-ally.enabledFrameworks": ["react", "i18next", "custom"], | ||
"i18n-ally.namespace": true, | ||
"i18n-ally.pathMatcher": "{locale}/{namespaces}.json", | ||
"i18n-ally.keystyle": "nested" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "custom-scope-range", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"i18next": "20.3.0", | ||
"i18next-xhr-backend": "3.2.2", | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"react-i18next": "11.9.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
examples/by-features/custom-scope-range/public/locales/en/pages/home.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"title": "Home" | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/by-features/custom-scope-range/public/locales/en/translation.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"title": "hello", | ||
"description": { | ||
"part1": "To get started, edit <1>src/App.js</1> and save to reload.", | ||
"part2": "Switch language between english and german using buttons above." | ||
}, | ||
"titlew": "ok", | ||
"foo": { | ||
"bar": "foobar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-header { | ||
background-color: #222; | ||
height: 100px; | ||
padding: 20px; | ||
color: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable no-unused-vars */ | ||
// eslint-disable-next-line no-use-before-define | ||
import React from 'react' | ||
import { Trans } from 'react-i18next' | ||
import { customScopeRangeFn } from './customScopeRange' | ||
import './App.css' | ||
|
||
// Component using the Trans component | ||
function MyComponent() { | ||
return ( | ||
<Trans i18nKey="translation:description.part1"> | ||
To get started, edit <code>src/App.js</code> and save to reload. | ||
</Trans> | ||
) | ||
} | ||
|
||
// page uses the hook | ||
function Page() { | ||
const { t } = customScopeRangeFn() | ||
|
||
return ( | ||
<div className="App"> | ||
<div className="App-intro"> | ||
<MyComponent /> | ||
</div> | ||
<div>{t('translation:description.part2')}</div> | ||
{/* plain <Trans>, #423 */} | ||
<Trans i18nKey="translation:description.part2">Fallback text</Trans> | ||
</div> | ||
) | ||
} | ||
|
||
// function with scope | ||
function Page2() { | ||
const { t } = customScopeRangeFn(['translation:foo']) | ||
|
||
// inside default namespace ("foo.bar") | ||
t('bar') | ||
|
||
// explicit namespace | ||
t('pages.home:title') | ||
t('pages/home:title') | ||
} | ||
|
||
// function with another scope | ||
function Page3() { | ||
const { t } = customScopeRangeFn('pages/home') | ||
|
||
t('title') | ||
|
||
// explicit namespace | ||
t('translation:title') | ||
} | ||
|
||
// function with scope in options | ||
function Page4() { | ||
const { t } = customScopeRangeFn('pages/home') | ||
|
||
t('title') | ||
|
||
// explicit namespace | ||
t('title', { ns: 'translation' }) | ||
} | ||
|
||
// component with scope in props | ||
function Page5() { | ||
const { t } = customScopeRangeFn('pages/home') | ||
|
||
return ( | ||
<div className="App"> | ||
<Trans t={t} i18nKey="title"></Trans> | ||
{/* explicit namespace */} | ||
<Trans t={t} i18nKey="title" ns="translation"></Trans> | ||
</div> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
examples/by-features/custom-scope-range/src/customScopeRange.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useTranslation as customScopeRangeFn } from 'react-i18next' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import React from 'react' | ||
import i18n from 'i18next' | ||
import { initReactI18next } from 'react-i18next' | ||
|
||
i18n | ||
.use(Backend) | ||
.use(initReactI18next) | ||
.init({ | ||
fallbackLng: 'en', | ||
debug: true, | ||
|
||
interpolation: { | ||
escapeValue: false, // not needed for react as it escapes by default | ||
}, | ||
}) | ||
|
||
export default i18n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-use-before-define | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App' | ||
|
||
import './i18n' | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters