Skip to content
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
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
783 changes: 781 additions & 2 deletions .pnp.cjs

Large diffs are not rendered by default.

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 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 not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/fsevents-patch-19706e7e35-10.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 not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
packageExtensions:
'@atls-ui-parts/text@*':
dependencies:
'@emotion/react': '*'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот с этим надо разобраться - почему он требует эмоушн хотя в зависимостях все есть. Проверь еще в гиперионе пожалуйста

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dependencies": {
    "csstype": "3.1.3"
  },
  "devDependencies": {
    "@emotion/styled": "11.11.0",
    "@types/react": "18.2.48",
    "@types/styled-system": "5.1.22",
    "react": "18.2.0",
    "styled-system": "5.1.5"
  },
  "peerDependencies": {
    "@emotion/styled": "11.11.0",
    "react": "18.2.0",
    "styled-system": "5.1.5"
  },
  "publishConfig": {
    "access": "public",
    "main": "dist/index.js",
    "typings": "dist/index.d.ts"
  }

Нам не нужно его явно в пирах получать?

@emotion/react вообще не фигурирует в зависимостях для текста в гипперионе

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тогда надо обязательно добавить.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

создай пожалуйста таску на это дело


compressionLevel: mixed

enableGlobalCache: false
Expand Down
3 changes: 3 additions & 0 deletions app-router/entrypoints/renderer/locales/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text": "text"
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
7 changes: 7 additions & 0 deletions pages-router/entrypoints/renderer/locales/ru.json
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"
}
5 changes: 5 additions & 0 deletions pages-router/entrypoints/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"scripts": {
"build": "yarn next build src --no-lint && cp -r ./src/.next/standalone ./dist && cp -r ./src/.next/static ./dist/src/.next/static && mv ./dist/src/server.js ./dist/src/index.cjs",
"dev": "yarn next dev src",
"generate-locales": "generate-locales ../../fragments ../../pages --out=ru",
"postinstall": "run generate-locales",
"prepack": "run build",
"start": "node dist/src/index.cjs"
},
Expand All @@ -15,13 +17,16 @@
"next": "14.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-intl": "6.6.2",
"styled-system": "5.1.5"
},
"devDependencies": {
"@app/home-page": "workspace:0.0.1",
"@formatjs/cli": "6.2.7",
"@types/node": "20.11.5",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"@ui/locales-generator": "workspace:0.0.1",
"@ui/theme": "workspace:0.0.1",
"typescript": "5.2.2"
}
Expand Down
11 changes: 8 additions & 3 deletions pages-router/entrypoints/renderer/src/pages/_app.tsx
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
4 changes: 4 additions & 0 deletions pages-router/fragments/navbar/locales/ru.json
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"
}
22 changes: 22 additions & 0 deletions pages-router/fragments/navbar/package.json
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": "*"
}
}
1 change: 1 addition & 0 deletions pages-router/fragments/navbar/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './navbar.component'
36 changes: 36 additions & 0 deletions pages-router/fragments/navbar/src/navbar.component.tsx
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>
)
}
3 changes: 3 additions & 0 deletions pages-router/fragments/sidebar/locales/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app.sidebar-fragment.identity": "SIDEBAR"
}
21 changes: 21 additions & 0 deletions pages-router/fragments/sidebar/package.json
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": "*"
}
}
1 change: 1 addition & 0 deletions pages-router/fragments/sidebar/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sidebar.component'
22 changes: 22 additions & 0 deletions pages-router/fragments/sidebar/src/sidebar.component.tsx
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>
)
4 changes: 4 additions & 0 deletions pages-router/pages/home/locales/ru.json
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"
}
12 changes: 9 additions & 3 deletions pages-router/pages/home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
"version": "0.0.1",
"main": "src/index.ts",
"dependencies": {
"@ui/hello": "workspace:0.0.1"
"@app/navbar-fragment": "workspace:0.0.1",
"@app/sidebar-fragment": "workspace:0.0.1",
"@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-dom": "18.2.0",
"react-intl": "6.6.2"
},
"peerDependencies": {
"react": "*",
"react-dom": "*"
"react-dom": "*",
"react-intl": "*"
}
}
36 changes: 28 additions & 8 deletions pages-router/pages/home/src/home.component.tsx
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
4 changes: 3 additions & 1 deletion ui/hello/src/hello.component.tsx
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>
)
54 changes: 54 additions & 0 deletions ui/locales/README.md
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
33 changes: 33 additions & 0 deletions ui/locales/package.json
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"
}
}
22 changes: 22 additions & 0 deletions ui/locales/src/generator.ts
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`)
1 change: 1 addition & 0 deletions ui/locales/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './generator'
1 change: 1 addition & 0 deletions ui/locales/src/locales-generator.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const defaultPaths = ['../../fragments', '../../pages']
1 change: 1 addition & 0 deletions ui/locales/src/merge-locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './merge-locales'
1 change: 1 addition & 0 deletions ui/locales/src/merge-locales/merge-locales.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type MergeLocalesType = (files: string[], outputPath: string) => void
Loading
Loading