-
Notifications
You must be signed in to change notification settings - Fork 32
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: extract i18n to class module #176
Conversation
Warning Rate limit exceeded@zzxming has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 13 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (10)
WalkthroughThe pull request introduces a comprehensive refactoring of the internationalization (i18n) configuration in the FluentEditor. The changes centralize language settings by introducing an Changes
Suggested labels
Suggested reviewers
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Nitpick comments (11)
packages/docs/fluent-editor/demos/i18n-custom.vue (1)
23-31
: Encapsulate translation data in a separate language resource file.
Encouraging the use of a dedicated language resource file (or JSON) to store and organize localized strings can improve maintainability. It helps avoid large configuration objects and makes further translations easier to add.packages/fluent-editor/src/config/types/editor-config.interface.ts (1)
17-20
: Ensure clarity of file parameter typing.
Changing from an explicitly typedfile: File
to an untyped parameter may introduce confusion or potential runtime errors. You might consider adding a TypeScript interface or type alias for thefile
parameter, clarifying how it should be consumed.packages/fluent-editor/src/i18n/index.ts (3)
5-8
: Document usage oflangText
more extensively.
It would be helpful to add a simple explanatory comment about whatlangText
typically contains (UI strings, button texts, etc.) and how it can be extended.
22-34
: Fallback warnings are user-friendly, consider integrating logging for i18n analytics.
When a requested language isn’t supported, the console warns appropriately. To further enhance i18n QA, some teams log unsupported languages or usage patterns for analytics or monitoring.Would you like me to show how to integrate a minimal logging utility for capturing these events?
41-48
: Check for concurrency or race conditions if changeLanguage is invoked repeatedly.
If multiple calls happen in quick succession, ensure event listeners or intermediate states don’t cause race conditions. You might want to queue or debounce changes if that becomes an issue in production.packages/fluent-editor/src/counter/index.ts (1)
36-36
: Handle missing or undefined translations gracefully.
Accessingthis.quill.langText.char
orthis.quill.langText.word
is fine when language text is guaranteed. Otherwise, consider providing a safe fallback in case these keys don’t exist.packages/fluent-editor/src/toolbar/toolbar-tip.ts (1)
23-24
: Robust language handling with optional checks.
Usingif (!this.quill.lang) return result
is a nice safeguard to avoid undefined references. Just confirm that all code paths use a safe fallback iflang
is not set.packages/fluent-editor/src/fluent-editor.ts (1)
35-36
: Explicitlang
andlangText
fields.
Defining them directly onFluentEditor
clarifies ownership and reduces confusion. Consider documenting their usage in a docstring to guide future maintainers.packages/fluent-editor/src/table/modules/table-operation-menu.ts (3)
54-54
: Consider syncing colorSubTitle on language change.
You updateDEFAULT_COLOR_SUBTITLE
afterCHANGE_LANGUAGE_EVENT
, but you do not updatethis.colorSubTitle
. If a user configures a custom color title, the language change might causeDEFAULT_COLOR_SUBTITLE
to shift, but the actualcolorSubTitle
remains stale.this.quill.on(CHANGE_LANGUAGE_EVENT, () => { this.destroy() this.DEFAULT_COLOR_SUBTITLE = this.quill.langText['sub-title-bg-color'] this.setDefaultMenu() + this.colorSubTitle + = this.options.color && this.options.color.text + ? this.options.color.text + : this.DEFAULT_COLOR_SUBTITLE })
69-69
: Avoid repeating the assignment toDEFAULT_COLOR_SUBTITLE
.
The same assignment also appears in the constructor (line 54). While this is logical for re-initialization after the language changes, consider wrapping this logic in a helper method to reduce duplication.
75-75
: Minor improvement: destructurelongText
fromthis.quill
.
Destructuring can be more concise and consistent with the rest of the code’s style.- const langText = this.quill.langText + const { langText } = this.quill
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
packages/docs/fluent-editor/demos/i18n-custom.vue
(1 hunks)packages/docs/fluent-editor/demos/i18n.vue
(1 hunks)packages/fluent-editor/src/config/types/editor-config.interface.ts
(1 hunks)packages/fluent-editor/src/counter/index.ts
(4 hunks)packages/fluent-editor/src/custom-clipboard.ts
(2 hunks)packages/fluent-editor/src/fluent-editor.ts
(5 hunks)packages/fluent-editor/src/i18n/index.ts
(1 hunks)packages/fluent-editor/src/link/modules/tooltip.ts
(1 hunks)packages/fluent-editor/src/table/modules/table-operation-menu.ts
(2 hunks)packages/fluent-editor/src/toolbar/toolbar-tip.ts
(2 hunks)
🔇 Additional comments (15)
packages/docs/fluent-editor/demos/i18n.vue (2)
24-26
: Initialization with reactive lang property looks appropriate.
This approach is straightforward, ensuring that changes in lang.value
propagate correctly through the editor’s i18n module.
33-33
: Check error handling when calling getModule('i18n').
If the i18n
module is absent for any reason, a null/undefined return may cause runtime errors. Consider gracefully handling scenarios where the i18n module has not been registered or loaded.
Want me to add a fallback check here to avoid disruptions if the module fails to load?
packages/fluent-editor/src/i18n/index.ts (2)
1-4
: Imports and default exports are well-organized.
The import structure is clear and descriptive, aiding readability.
36-39
: Synchronize with the new quill.langText
fields.
Updating both this.quill.langText
and this.quill.lang
is a succinct approach. Ensure no conflicting leftover references to old langText
or direct lang
usage continue in the code elsewhere.
packages/fluent-editor/src/counter/index.ts (3)
14-14
: Great consistency in event refactoring.
The switch from quill.on
to this.quill.emitter.on
aligns well with the broader refactor, ensuring consistency and centralization of event handling throughout the codebase.
25-25
: Directly accessing langText
is clear and concise.
Referencing this.quill.langText['counter-template']
keeps the code straightforward and consistent with the new i18n approach. Just confirm that this key always exists to avoid potential runtime errors.
46-46
: Ensure fallback for 'counter-limit-tips' key.
Similarly, verify that 'counter-limit-tips'
exists in this.quill.langText
to avoid potential edge cases if the translation key is missing.
packages/fluent-editor/src/toolbar/toolbar-tip.ts (1)
14-14
: Consistent transition to emitter
for language event.
This is in line with the codebase refactor. Good job maintaining a uniform approach for handling CHANGE_LANGUAGE_EVENT
across modules.
packages/fluent-editor/src/fluent-editor.ts (4)
6-6
: Consolidated imports look good.
Importing getListValue
, ICONS_CONFIG
, and inputFile
from ./config
keeps relevant utilities in one place, aligning with the modular design of the refactor.
17-17
: i18n module import is well-organized.
Introducing { I18N }
here centralizes language handling and is consistent with the pull request goal of extracting and modularizing i18n functionality.
51-51
: Activating i18n by default.
Setting 'i18n': true
in the defaults ensures the feature is always available, supporting a straightforward internationalization setup.
164-164
: Registering the i18n module as core functionality.
Adding 'modules/i18n': I18N
seamlessly integrates the module into FluentEditor, highlighting i18n's importance in your architecture.
packages/fluent-editor/src/link/modules/tooltip.ts (2)
43-43
: Consistent event handling approach.
Transitioning from this.quill.on
to this.quill.emitter.on
matches the refactoring in other classes, creating a uniform event orchestration pattern.
50-50
: Safely reference linkplaceholder
.
Using this.quill.langText?.linkplaceholder
is good, but verify that a sensible fallback is provided if the property is missing or undefined.
packages/fluent-editor/src/custom-clipboard.ts (1)
474-474
: Ensure the i18n key 'img-error'
is always defined.
If the 'img-error'
key is missing or changes, the fallback logic may not work as expected. Consider providing a default message to ensure stable behavior.
0605cca
to
9f8fdba
Compare
export class FluentEditor extends Quill { | ||
isFullscreen: boolean = false | ||
options: IEditorConfig & ExpandedQuillOptions | ||
lang: string | ||
langText: Record<string, string> |
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.
@zzxming 这两个变量为什么从 quill.options 移到了 quill 呢?直接放到 quill 中和放到 quill.options 中,一般如何选择呢?
另外是不是从 i18n 模块也能获取这两个变量,比如:this.quill.getModule('i18n').options.lang,这样是不是就重复了?
之前可能是没有抽取 i18n 模块,所以需要有一个地方承载 lang / langText,现在有 i18n 模块了,我觉得挂在 quill 的这两个变量是没有必要的。
不过这个不太要紧,我先合入,可以后续持续优化。
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.
你说的有道理,这个是我在删依赖包的时候顺手改的,没注意太多。
但是我觉得在 this.quill 上挂 lang
这个变量还是有用的,i18n 是处理编辑器内文字的,有这个也可以更方便的获取当前编辑器的语,可以挂 getter,这样要修改还是要通过 changeLanguage 改,但是获取可以直接 quill.lang
获取。langText
我可以抽离一个函数去获取对应文本,这样也不用每次获取文本都要写一长串了
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Refactor
Bug Fixes