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

I18n dev #1108

Merged
merged 5 commits into from
May 21, 2022
Merged

I18n dev #1108

merged 5 commits into from
May 21, 2022

Conversation

luoyunchong
Copy link
Collaborator

@luoyunchong luoyunchong commented May 19, 2022

新增FreeSql、FreeSql.DbContext 异常信息 国际化语言.

默认语言与操作系统的显示语言有关,也可指定具体的语言

  • 英文
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
  • 中文
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hans");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans");

@2881099
Copy link
Collaborator

2881099 commented May 19, 2022

如果操作系统不是 en-US,zh-Hans 有可能出错,比如台湾、西班牙。很多国内的linux系统是英文区域化设置,默认却不显示中文错误。

我的看法:确定只有两种国际化信息,可以不依赖 Settings 这种模式。比如在 FreeSqlBuilder 做一个 UseEnglishMessage(true) 开启英文提示,默认仍然是中文。这样做还不影响老用户习惯。

一起讨论下 @densen2014

@densen2014
Copy link
Member

只判断 zh开头应该可以的吧,然后可选强制指定英文/中文异常提示就完美了。

//当前操作系统是否为简体中文
public static bool IsChineseSimple(){
return System.Threading.Thread.CurrentThread.CurrentCulture.Name.StartWith( "zh-");
}

zh-HK 0x0C04 中文(香港特别行政区,中国)
zh-MO 0x1404 中文(澳门特别行政区)
zh-CN 0x0804 中文(中国)
zh-Hans 0x0004 中文(简体)
zh-SG 0x1004 中文(新加坡)
zh-TW 0x0404 中文(台湾)
zh-Hant 0x7C04 中文(繁体)

@densen2014
Copy link
Member

如果操作系统不是 en-US,zh-Hans 有可能出错,比如台湾、西班牙。很多国内的linux系统是英文区域化设置,默认却不显示中文错误。

非中文环境直接出英文提示我觉得没啥问题,国际化按惯例走呗,build到时候加一行console提示可强制指定语言之类就行

@2881099
Copy link
Collaborator

2881099 commented May 20, 2022

支持,可以依据 System.Threading.Thread.CurrentThread.CurrentCulture.Name 作为默认语言判断,也可以强制指定。

不建议修改 System.Threading.Thread.CurrentThread.CurrentCulture.Name 来指定语言,因为可能影响到其他 dll,他们可能依赖这些区域化设置,比如数字、日期 ToString 都会受到影响。

@densen2014
Copy link
Member

万万不可直接设置这个,污染太大了

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hans");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans");

@luoyunchong
Copy link
Collaborator Author

把英文的作为默认语言,把中文换成CoreStrings.zh-Hans.resx存储

当用户不是英文,也不是中文环境时,就会显示英文的资源。

@2881099
Copy link
Collaborator

2881099 commented May 20, 2022

我担心这种情况,A用户发布了两个服务器程序,一台显示中文错误,一台显示英文错误,然后他需要找两次答案。

@luoyunchong
Copy link
Collaborator Author

luoyunchong commented May 20, 2022

默认根据当前操作系统语言来,如果想在中文系统下,显示英文的错误信息,又不想改变CurrentUICulture的值,可通过如下方式

FreeSql.CoreStrings.Culture = new System.Globalization.CultureInfo("en-US");
FreeSql.DbContextStrings.Culture = new System.Globalization.CultureInfo("en-US");
FreeSql.CoreStrings.Culture = new System.Globalization.CultureInfo("zh-Hans");
FreeSql.DbContextStrings.Culture = new System.Globalization.CultureInfo("zh-Hans");

@2881099 2881099 merged commit 4235a74 into master May 21, 2022
2881099 added a commit that referenced this pull request May 21, 2022
2881099 added a commit that referenced this pull request May 24, 2022
2881099 added a commit that referenced this pull request May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants