-
Notifications
You must be signed in to change notification settings - Fork 329
[fit] Enhance FIT's i18n capabilities by parsing locales from HTTP requests. #275
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
Merged
CodeCasterX
merged 25 commits into
ModelEngine-Group:main
from
Yager-42:fit-feature-i18n
Sep 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
26a293e
[fit] 实现请求地区解析
Yager-42 21fe248
[fit] 实现国际化消息处理器,完善测试
Yager-42 c79a348
[fit] 完善注释
Yager-42 8a97b05
[fit] 完善注释
Yager-42 53f1c3e
[fit] 修改校验处理默认使用的插值器
Yager-42 bcb4f86
[fit] 修改校验处理插值器,提供默认地区设置功能
Yager-42 f1b5130
初步实现
Yager-42 dfec108
可用的多插件地区解析实现
Yager-42 c7afa65
完善注释
Yager-42 c82354c
恢复样例
Yager-42 956948e
修改实现
Yager-42 1ea4da2
完善代码
Yager-42 ffe6777
删除pom中的旧实现残留
Yager-42 88ce487
修改错误方法名,为工具类提供测试方法。
Yager-42 90ff96b
修改格式。
Yager-42 dac1a24
修改格式
Yager-42 0493ec8
删除localecontext
Yager-42 f849028
修复逻辑错误,完善格式
Yager-42 f530625
完善格式
Yager-42 ecb2134
修复错误
Yager-42 53a6a7a
修复错误
Yager-42 9b695ca
完善测试
Yager-42 c8a6d16
修复错误
Yager-42 57ac0b1
为插值方法提供null值保护
Yager-42 4976605
完善格式以及优化null检查
Yager-42 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
This file contains hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
...va/fit-util/src/test/java/modelengine/fitframework/util/i18n/LocaleContextHolderTest.java
This file contains hidden or 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,102 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.fitframework.util.i18n; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * {@link LocaleContextHolder} 的单元测试。 | ||
| * | ||
| * @author 阮睿 | ||
| * @since 2025-09-09 | ||
| */ | ||
| @DisplayName("测试 LocaleContextHolder") | ||
| public class LocaleContextHolderTest { | ||
| @AfterEach | ||
| void tearDown() { | ||
| LocaleContextHolder.clear(); | ||
| } | ||
|
|
||
| @Nested | ||
| @DisplayName("Test method: setLocaleContext and getLocaleContext") | ||
| class TestSetAndGetLocaleContext { | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale context with zh_CN then return the same locale context") | ||
| void givenLocaleContextWithZhCNThenReturnSameLocaleContext() { | ||
| LocaleContext localeContext = new LocaleContext(Locale.SIMPLIFIED_CHINESE); | ||
| LocaleContextHolder.setLocaleContext(localeContext); | ||
| assertThat(LocaleContextHolder.getLocaleContext()).isEqualTo(localeContext); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale context with en_US then return the same locale context") | ||
| void givenLocaleContextWithEnUSThenReturnSameLocaleContext() { | ||
| LocaleContext localeContext = new LocaleContext(Locale.US); | ||
| LocaleContextHolder.setLocaleContext(localeContext); | ||
| assertThat(LocaleContextHolder.getLocaleContext()).isEqualTo(localeContext); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given null locale context then not set and return null") | ||
| void givenNullLocaleContextThenReturnNull() { | ||
| LocaleContextHolder.setLocaleContext(null); | ||
| assertThat(LocaleContextHolder.getLocaleContext()).isNull(); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| @DisplayName("Test method: getLocale") | ||
| class TestGetLocale { | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale context with zh_CN then return zh_CN locale") | ||
| void givenLocaleContextWithZhCNThenReturnZhCNLocale() { | ||
| LocaleContext localeContext = new LocaleContext(Locale.SIMPLIFIED_CHINESE); | ||
| LocaleContextHolder.setLocaleContext(localeContext); | ||
| assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.SIMPLIFIED_CHINESE); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale context with en_US then return en_US locale") | ||
| void givenLocaleContextWithEnUSThenReturnEnUSLocale() { | ||
| LocaleContext localeContext = new LocaleContext(Locale.US); | ||
| LocaleContextHolder.setLocaleContext(localeContext); | ||
| assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.US); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given no locale context then return null") | ||
| void givenNoLocaleContextThenReturnNull() { | ||
| LocaleContextHolder.clear(); | ||
| assertThat(LocaleContextHolder.getLocale()).isNull(); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| @DisplayName("Test method: clear") | ||
| class TestClear { | ||
|
|
||
| @Test | ||
| @DisplayName("Given existing locale context then clear it") | ||
| void givenExistingLocaleContextThenClearIt() { | ||
| LocaleContext localeContext = new LocaleContext(Locale.SIMPLIFIED_CHINESE); | ||
| LocaleContextHolder.setLocaleContext(localeContext); | ||
| assertThat(LocaleContextHolder.getLocaleContext()).isNotNull(); | ||
|
|
||
| LocaleContextHolder.clear(); | ||
| assertThat(LocaleContextHolder.getLocaleContext()).isNull(); | ||
| } | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
...fit/java/fit-util/src/test/java/modelengine/fitframework/util/i18n/LocaleContextTest.java
This file contains hidden or 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,53 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.fitframework.util.i18n; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * {@link LocaleContext} 的单元测试。 | ||
| * | ||
| * @author 阮睿 | ||
| * @since 2025-09-09 | ||
| */ | ||
| @DisplayName("测试 LocaleContext") | ||
| public class LocaleContextTest { | ||
| @Nested | ||
| @DisplayName("Test method: constructor and getLocale()") | ||
| class TestConstructorAndGetLocale { | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale is zh_CN then return the same locale") | ||
| void givenZhCNThenReturnSameLocale() { | ||
| Locale locale = Locale.SIMPLIFIED_CHINESE; | ||
| LocaleContext localeContext = new LocaleContext(locale); | ||
| assertThat(localeContext.getLocale()).isEqualTo(locale); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale is en_US then return the same locale") | ||
| void givenEnUSThenReturnSameLocale() { | ||
| Locale locale = Locale.US; | ||
| LocaleContext localeContext = new LocaleContext(locale); | ||
| assertThat(localeContext.getLocale()).isEqualTo(locale); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given locale is null then return null") | ||
| void givenNullThenReturnNull() { | ||
| LocaleContext localeContext = new LocaleContext(null); | ||
| assertThat(localeContext.getLocale()).isNull(); | ||
| } | ||
| } | ||
| } | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.