generated from atls-lab/template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: locales xtraction #4
Open
FrankJaskon
wants to merge
5
commits into
master
Choose a base branch
from
feat/extract-translations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ae3ae86
feat: add extraction of translations
FrankJaskon 41fec05
feat: add locales-generator package
FrankJaskon c10b69c
chore: format
FrankJaskon a3eb14d
chore: add constants
FrankJaskon 2cd566f
fix: rename dist to temporary
FrankJaskon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+1.54 KB
.yarn/cache/@atls-config-prettier-npm-0.0.5-0a66208dbc-f501e0d241.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.83 KB
.yarn/cache/@babel-helper-string-parser-npm-7.23.4-b1f0d030c3-c352082474.zip
Binary file not shown.
Binary file added
BIN
+17.5 KB
.yarn/cache/@babel-helper-validator-identifier-npm-7.22.20-18305bb306-df882d2675.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+122 KB
.yarn/cache/@formatjs-ecma402-abstract-npm-1.18.2-281c9afdd0-e761653887.zip
Binary file not shown.
Binary file added
BIN
+4.83 KB
.yarn/cache/@formatjs-fast-memoize-npm-2.2.0-4a46a61b8b-8697fe72a7.zip
Binary file not shown.
Binary file added
BIN
+54.1 KB
.yarn/cache/@formatjs-icu-messageformat-parser-npm-2.7.6-59cd895220-5baf9c1cf4.zip
Binary file not shown.
Binary file added
BIN
+13.7 KB
.yarn/cache/@formatjs-icu-skeleton-parser-npm-1.8.0-0f1fd4bf3f-8cd96d9075.zip
Binary file not shown.
Binary file added
BIN
+5.98 MB
.yarn/cache/@formatjs-intl-displaynames-npm-6.6.6-e035dc475b-b3c4ed7e7e.zip
Binary file not shown.
Binary file added
BIN
+403 KB
.yarn/cache/@formatjs-intl-listformat-npm-7.5.5-496f84d41c-78907a1021.zip
Binary file not shown.
Binary file added
BIN
+41.2 KB
.yarn/cache/@formatjs-intl-localematcher-npm-0.5.4-e30cfcd8fd-780cb29b42.zip
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+31.5 MB
...darwin-arm64-npm-14.1.0-6d433a23a7-10.zip → ...inux-x64-gnu-npm-14.1.0-5a9ae6f5df-10.zip
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+2.96 KB
.yarn/cache/@types-babel__standalone-npm-7.1.6-e466ac00c7-86f87a278a.zip
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.48 KB
.yarn/cache/@types-hoist-non-react-statics-npm-3.3.5-98b8d8e47b-b645b062a2.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.85 KB
.yarn/cache/import-sort-parser-typescript-npm-6.0.0-97a472ec0a-b98b05011f.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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 @@ | ||
{ | ||
"text": "text" | ||
} |
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 |
---|---|---|
|
@@ -21,9 +21,11 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"linterIgnorePatterns": [ | ||
"**/next.config.js" | ||
"**/next.config.js", | ||
"temporary" | ||
], | ||
"typecheckIgnorePatterns": [ | ||
"**/next-env.d.ts" | ||
"**/next-env.d.ts", | ||
"temporary" | ||
] | ||
} |
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 @@ | ||
{ | ||
"app.navbar.hello": "HELLO TOO FROM NAVBAR", | ||
"app.navbar_fragment.identity": "IDENTITY", | ||
"app.sidebar-fragment.identity": "SIDEBAR", | ||
"app.home_page.content": "CONTENT", | ||
"app.home_page.hello": "HELLO FROM HOME" | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import React from 'react' | ||
import { IntlProvider } from 'react-intl' | ||
|
||
import { ThemeProvider } from '@ui/theme' | ||
|
||
import messages from '../../locales/ru.json' | ||
|
||
const App = ({ Component, pageProps, ...props }) => ( | ||
<ThemeProvider> | ||
<Component {...pageProps} {...props} /> | ||
</ThemeProvider> | ||
<IntlProvider defaultLocale='ru' locale='ru' messages={messages}> | ||
<ThemeProvider> | ||
<Component {...pageProps} {...props} /> | ||
</ThemeProvider> | ||
</IntlProvider> | ||
) | ||
|
||
export default App |
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,4 @@ | ||
{ | ||
"app.navbar.hello": "HELLO TOO FROM NAVBAR", | ||
"app.navbar_fragment.identity": "IDENTITY" | ||
} |
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,22 @@ | ||
{ | ||
"name": "@app/navbar-fragment", | ||
"version": "0.0.1", | ||
"main": "src/index.ts", | ||
"dependencies": { | ||
"@ui/hello": "workspace:0.0.1", | ||
"@ui/layout": "workspace:0.0.1", | ||
"@ui/text": "workspace:0.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "18.2.48", | ||
"@types/react-dom": "18.2.18", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-intl": "6.6.2" | ||
}, | ||
"peerDependencies": { | ||
"react": "*", | ||
"react-dom": "*", | ||
"react-intl": "*" | ||
} | ||
} |
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 * from './navbar.component' |
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,36 @@ | ||
import React from 'react' | ||
import { FormattedMessage } from 'react-intl' | ||
import { useIntl } from 'react-intl' | ||
|
||
import { Hello } from '@ui/hello' | ||
import { Box } from '@ui/layout' | ||
import { Column } from '@ui/layout' | ||
import { Text } from '@ui/text' | ||
|
||
export const Navbar = () => { | ||
const { formatMessage } = useIntl() | ||
return ( | ||
<Column gap={20}> | ||
<Box | ||
justifyContent='center' | ||
alignItems='center' | ||
padding='huge' | ||
backgroundColor='darkRed' | ||
border='boldLightGray' | ||
boxShadow='black.fifteenHundredthsTransparent' | ||
height={50} | ||
gap={20} | ||
> | ||
<Text color='white'> | ||
<FormattedMessage id='app.navbar_fragment.identity' defaultMessage='IDENTITY' /> | ||
</Text> | ||
<Hello | ||
hello={formatMessage({ | ||
id: 'app.navbar.hello', | ||
defaultMessage: 'HELLO TOO FROM NAVBAR', | ||
})} | ||
/> | ||
</Box> | ||
</Column> | ||
) | ||
} |
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 @@ | ||
{ | ||
"app.sidebar-fragment.identity": "SIDEBAR" | ||
} |
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,21 @@ | ||
{ | ||
"name": "@app/sidebar-fragment", | ||
"version": "0.0.1", | ||
"main": "src/index.ts", | ||
"dependencies": { | ||
"@ui/layout": "workspace:0.0.1", | ||
"@ui/text": "workspace:0.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "18.2.48", | ||
"@types/react-dom": "18.2.18", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-intl": "6.6.2" | ||
}, | ||
"peerDependencies": { | ||
"react": "*", | ||
"react-dom": "*", | ||
"react-intl": "*" | ||
} | ||
} |
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 * from './sidebar.component' |
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,22 @@ | ||
import React from 'react' | ||
import { FormattedMessage } from 'react-intl' | ||
|
||
import { Box } from '@ui/layout' | ||
import { Text } from '@ui/text' | ||
|
||
export const Sidebar = () => ( | ||
<Box | ||
justifyContent='center' | ||
alignItems='center' | ||
height='calc(100vh - 50px)' | ||
width={200} | ||
padding='huge' | ||
backgroundColor='darkRed' | ||
borderTop='boldLightGray' | ||
borderRight='boldLightGray' | ||
> | ||
<Text> | ||
<FormattedMessage id='app.sidebar-fragment.identity' defaultMessage='SIDEBAR' /> | ||
</Text> | ||
</Box> | ||
) |
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,4 @@ | ||
{ | ||
"app.home_page.content": "CONTENT", | ||
"app.home_page.hello": "HELLO FROM HOME" | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,32 @@ | ||
import React from 'react' | ||
import React from 'react' | ||
import { FormattedMessage } from 'react-intl' | ||
import { useIntl } from 'react-intl' | ||
|
||
import { Hello } from '@ui/hello' | ||
import { Navbar } from '@app/navbar-fragment' | ||
import { Sidebar } from '@app/sidebar-fragment' | ||
import { Hello } from '@ui/hello' | ||
import { Box } from '@ui/layout' | ||
import { Row } from '@ui/layout' | ||
import { Text } from '@ui/text' | ||
|
||
const HomePage = () => ( | ||
<> | ||
<h1>HELLO</h1> | ||
<Hello /> | ||
</> | ||
) | ||
const HomePage = () => { | ||
const { formatMessage } = useIntl() | ||
return ( | ||
<> | ||
<Navbar /> | ||
<Row fill> | ||
<Sidebar /> | ||
<Box gap={20}> | ||
<Hello | ||
hello={formatMessage({ id: 'app.home_page.hello', defaultMessage: 'HELLO FROM HOME' })} | ||
/> | ||
<Text> | ||
<FormattedMessage id='app.home_page.content' defaultMessage='CONTENT' /> | ||
</Text> | ||
</Box> | ||
</Row> | ||
</> | ||
) | ||
} | ||
|
||
export default HomePage |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import React from 'react' | ||
|
||
export const Hello = () => <i>HELLO</i> | ||
export const Hello = ({ hello }: { hello?: string }) => ( | ||
<i>{hello ?? 'GLOOMY HELLO WITHOUT TRANSLATION'}</i> | ||
) |
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,54 @@ | ||
# LOCALES-GENERATOR 0.0.1 | ||
|
||
Скрипт для автоматической генерации переводов `react-inl`. | ||
|
||
Создаёт на уровне энтрипоинта `locales/[localName].json` файл, содержащий все переводы энтрипоинта на основе `id` и `defaultMessages` | ||
|
||
Для работы обязательно указывать в `formatMessage` или `FormattedMessage` уникальный `id` и текст перевода в `defaultMessages`. | ||
|
||
Пример валидного компонента: | ||
|
||
```html | ||
<Hello | ||
hello={formatMessage({ id: 'app.home_page.hello', defaultMessage: 'HELLO FROM HOME' })} | ||
/> | ||
<Text> | ||
<FormattedMessage id='app.home_page.content' defaultMessage='CONTENT' /> | ||
</Text> | ||
``` | ||
|
||
--- | ||
|
||
## Установка | ||
|
||
Устанавливаем на уровне энтрипоинта: `yarn add -D @atls-ui-generators/locales` | ||
|
||
## Запуск | ||
|
||
Для запуска необходимо добавить скрипты в `package.json` ентрипоинта. | ||
|
||
Пример скриптов: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"generate-locales": "generate-locales ../../fragments ../../pages --out=en", | ||
"postinstall": "run generate-locales" | ||
} | ||
} | ||
``` | ||
|
||
### Входные аргументы | ||
|
||
`generate-locales` принимает следующие аргументы: | ||
|
||
1. **componentPaths** - Относительный список путей от `package.json` энтрипоинта по которым будет производится поиск переводов \*_необязательный_. | ||
- Принимается неограниченное кол-во аргументов. "generate-locales path1 path2 ...pathN" | ||
- Если не указать массив путей в аргументах, скрипт будет проходить по фрагментам и страницам текущего энтрипоинта | ||
2. **localName** - Название локали \*_необязательный_. | ||
- Указывается после `-out=` | ||
- Если не указывать. По умолчанию берётся локаль = ru | ||
|
||
--- | ||
|
||
# Changelog |
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,33 @@ | ||
{ | ||
"name": "@ui/locales-generator", | ||
"version": "0.0.1", | ||
"license": "BSD-3-Clause", | ||
"main": "src/index.ts", | ||
"typings": "temporary/index.d.ts", | ||
"bin": { | ||
"generate-locales": "temporary/generator.js" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "yarn library build", | ||
"prepack": "yarn run build", | ||
"postpack": "rm -rf dist" | ||
}, | ||
"dependencies": { | ||
"@atls/config-prettier": "0.0.5", | ||
"@atls/prettier-plugin": "0.0.7", | ||
"@babel/standalone": "7.22.20", | ||
"camelcase": "6.3.0", | ||
"commander": "9.5.0", | ||
"prettier": "2.8.8" | ||
}, | ||
"devDependencies": { | ||
"@types/babel__standalone": "7.1.6", | ||
"@types/prettier": "2.7.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,22 @@ | ||
import { defaultPaths } from './locales-generator.constants' | ||
import { mergeLocales } from './merge-locales' | ||
import { processDirectory } from './process-directory' | ||
|
||
const allLocales = [] | ||
let outputFile = 'ru' | ||
const argPaths: string[] = [] | ||
|
||
// @ts-ignore | ||
process.argv.slice(2).forEach((arg) => { | ||
if (!arg.startsWith('--out=')) { | ||
argPaths.push(arg) | ||
} else { | ||
// eslint-disable-next-line prefer-destructuring | ||
outputFile = arg.split('=')[1] | ||
} | ||
}) | ||
const paths = argPaths.length ? argPaths : defaultPaths | ||
|
||
paths.forEach((path) => processDirectory(path, 'locales', allLocales, outputFile)) | ||
|
||
mergeLocales(allLocales, `./locales/${outputFile}.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 @@ | ||
export * from './generator' |
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 const defaultPaths = ['../../fragments', '../../pages'] |
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 * from './merge-locales' |
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 type MergeLocalesType = (files: string[], outputPath: string) => void |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вот с этим надо разобраться - почему он требует эмоушн хотя в зависимостях все есть. Проверь еще в гиперионе пожалуйста
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нам не нужно его явно в пирах получать?
@emotion/react
вообще не фигурирует в зависимостях для текста в гипперионеThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тогда надо обязательно добавить.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
создай пожалуйста таску на это дело