[go: up one dir, main page]

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

refactor(i18n): new hook api #7273

Merged
merged 1 commit into from
Jun 20, 2024
Merged

refactor(i18n): new hook api #7273

merged 1 commit into from
Jun 20, 2024

Conversation

EYHN
Copy link
Member
@EYHN EYHN commented Jun 19, 2024

NEW HOOK API

useI18n: same as useAFFiNEI18N, with additional APIs

import { useI18n } from '@affine/i18n'

const i18n = useI18n()
i18n['hello world']() -> 你好世界

NEW GLOBAL i18n Instance

I18n: use i18n capabilities outside of React

import { I18n } from '@affine/i18n'

I18n['hello world']() -> 你好世界

NEW TYPES

I18nKeys -> all i18n keys

I18nString -> An i18n message (key&options)
transfer and store i18n text outside of React

const msg: I18nString = {
  key: 'helloworld',
  options: {
    arg1: '123'
  }
}

I18n.t(msg) -> 你好世界123

before:

registerCommand('open-page', {
  name: t('command.open-page') 
  // ^- translation happens here, 
})

after:

registerCommand('open-page', {
  name: { key: 'command.open-page' }
  // ^- store I18nString here, translate when the command render to UI
})

Copy link
graphite-app bot commented Jun 19, 2024

Your org has enabled the Graphite merge queue for merging into canary

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Member Author
EYHN commented Jun 19, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @EYHN and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added docs Improvements or additions to documentation mod:i18n Related to i18n mod:component test Related to test cases app:core labels Jun 19, 2024
@EYHN EYHN marked this pull request as ready for review June 19, 2024 10:33
Copy link
nx-cloud bot commented Jun 19, 2024

Copy link
codecov bot commented Jun 19, 2024

Codecov Report

Attention: Patch coverage is 13.24503% with 131 lines in your changes missing coverage. Please review.

Project coverage is 58.35%. Comparing base (5b0f563) to head (7c0a686).

Files Patch % Lines
...re/src/components/affine/page-properties/table.tsx 0.00% 8 Missing ⚠️
packages/frontend/i18n/src/i18n.ts 69.23% 8 Missing ⚠️
...es/frontend/core/src/hooks/affine/use-shortcuts.ts 0.00% 6 Missing ⚠️
...omponents/app-sidebar/app-updater-button/index.tsx 0.00% 5 Missing ⚠️
...end/core/src/components/affine/auth/send-email.tsx 0.00% 4 Missing ⚠️
...ne/page-properties/property-row-value-renderer.tsx 0.00% 4 Missing ⚠️
...src/components/page-list/docs/page-list-header.tsx 0.00% 4 Missing ⚠️
...d/core/src/components/page-list/operation-cell.tsx 0.00% 4 Missing ⚠️
...ore/src/components/page-list/group-definitions.tsx 0.00% 3 Missing ⚠️
...ntend/core/src/components/page-list/page-group.tsx 0.00% 3 Missing ⚠️
... and 71 more
Additional details and impacted files
@@            Coverage Diff             @@
##           canary    #7273      +/-   ##
==========================================
+ Coverage   58.12%   58.35%   +0.23%     
==========================================
  Files         841      841              
  Lines       36531    36542      +11     
  Branches     3929     3931       +2     
==========================================
+ Hits        21232    21325      +93     
+ Misses      15006    14921      -85     
- Partials      293      296       +3     
Flag Coverage Δ
server-test 77.52% <ø> (+0.07%) ⬆️
unittest 29.08% <13.24%> (+0.54%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EYHN EYHN force-pushed the eyhn/refactor/i18n-hook branch 2 times, most recently from 4851d2d to 0e43f7b Compare June 19, 2024 10:58
Copy link
graphite-app bot commented Jun 19, 2024

Merge activity

  • Jun 19, 7:13 AM EDT: EYHN added this pull request to the Graphite merge queue.
  • Jun 19, 7:28 AM EDT: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: '3, 2, 1 Launch', 'Server E2E Test 1/3').
  • Jun 19, 10:19 PM EDT: EYHN added this pull request to the Graphite merge queue.
  • Jun 19, 10:32 PM EDT: EYHN merged this pull request with the Graphite merge queue.

EYHN added a commit that referenced this pull request Jun 19, 2024
# NEW HOOK API

`useI18n`: same as `useAFFiNEI18N`, with additional APIs

```ts
import { useI18n } from '@affine/i18n'

const i18n = useI18n()
i18n['hello world']() -> 你好世界
```

# NEW GLOBAL i18n Instance

`I18n`: use i18n capabilities outside of React

```ts
import { I18n } from '@affine/i18n'

I18n['hello world']() -> 你好世界
```

# NEW TYPES

`I18nKeys` -> all i18n keys

`I18nString` -> An i18n message (key&options)
transfer and store i18n text outside of React
```ts
const msg: I18nString = {
  key: 'helloworld',
  options: {
    arg1: '123'
  }
}

I18n.t(msg) -> 你好世界123
```

before:

```ts
registerCommand('open-page', {
  name: t('command.open-page')
  // ^- translation happens here,
})
```

after:

```ts
registerCommand('open-page', {
  name: { key: 'command.open-page' }
  // ^- store I18nString here, translate when the command render to UI
})
```
Copy link
Member
@forehalo forehalo left a comment

Choose a reason for hiding this comment

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

i18n for server errors can be configured now, it's time to use it

# NEW HOOK API

`useI18n`: same as `useAFFiNEI18N`, with additional APIs

```ts
import { useI18n } from '@affine/i18n'

const i18n = useI18n()
i18n['hello world']() -> 你好世界
```

# NEW GLOBAL i18n Instance

`I18n`: use i18n capabilities outside of React

```ts
import { I18n } from '@affine/i18n'

I18n['hello world']() -> 你好世界
```

# NEW TYPES

`I18nKeys` -> all i18n keys

`I18nString` -> An i18n message (key&options)
transfer and store i18n text outside of React
```ts
const msg: I18nString = {
  key: 'helloworld',
  options: {
    arg1: '123'
  }
}

I18n.t(msg) -> 你好世界123
```

before:

```ts
registerCommand('open-page', {
  name: t('command.open-page')
  // ^- translation happens here,
})
```

after:

```ts
registerCommand('open-page', {
  name: { key: 'command.open-page' }
  // ^- store I18nString here, translate when the command render to UI
})
```
@graphite-app graphite-app bot merged commit 7c0a686 into canary Jun 20, 2024
33 checks passed
@graphite-app graphite-app bot deleted the eyhn/refactor/i18n-hook branch June 20, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:core docs Improvements or additions to documentation mod:component mod:i18n Related to i18n test Related to test cases
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants