我有一个以印度为基础的应用程序,我将文化设置为:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-IN");
上面的代码是在调用Window - InitializeComponent方法之前设置的.
这仍然是在所有TextBox中显示$作为CurrencySymbol.
如果我将TextBox绑定如下,则显示"Rs".作为CurrencySymbol:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-IN");
Run Code Online (Sandbox Code Playgroud) 另一个简单问题.我有不同语言的网站.如果我想从资源文件中访问一个字符串,我会像这样使用它
Resources.MyResourceFile.MyStringIdentifier
Run Code Online (Sandbox Code Playgroud)
很容易.这样我在编译期间就知道资源字符串存在.
现在,只有当我想使用当前的文化时,这才有效.有时我需要指定一种特定的文化(假设当前用户使用德语作为语言,但他的操作会触发将消息发送给其他用户,这些用户将使用收件人的语言).现在,我看到两个选择:
Resources.MyResourceFile.ResourceManager.GetString("MyStringIdentifier", neededCulturInfo)
Run Code Online (Sandbox Code Playgroud)
另一个是改变当前线程的文化信息,我需要做几次.
还有第三种方式吗?在编译时告诉我资源存在但不需要一直改变线程文化的东西?
asp.net resources cultureinfo internationalization currentuiculture
我正在开发一个.net 4.5应用程序,需要多语言支持多文化等.
以下是国家/语言的示例列表
对于上述所有内容,可以根据上述文化名称创建CultureInfo对象
当用户进入站点时,我将Thread.CurrentThread.CurrentCulture和Thread.CurrentThread.CurrentUICulture设置为使用上述名称创建的文化,例如.
Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE", false)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE", false)
Run Code Online (Sandbox Code Playgroud)
以上所有名称均为有效的文化名称.
不,但我需要在俄罗斯添加另一种文化名称,英语.但问题是代码en-RU无效,所以当我创建时,new CultureInfo("en-RU", false)
我得到一个CultureNotFoundException,因为en-RU无效.
有了这种文化,我希望俄罗斯的格式等数字,日期等,但我希望网站上的语言是英语.是否可以使用国家/地区(俄罗斯)的行为为无效的文化名称创建自定义CultureInfo对象?
我有一个针对.NET Framework 4.7.1的ASP.NET MVC 4应用程序,如果操作包含异步调用,则存在Controller和View之间不共享文化的问题.
我正在引用NuGet包Microsoft.AspNet.Mvc
5.2.3(可以在5.2.4中复制).
这是Controller中的代码:
public class CulturesTestController : Controller
{
public async Task<ActionResult> Index(string value)
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("fi-FI");
Thread.CurrentThread.CurrentUICulture =
CultureInfo.GetCultureInfo("fi-FI");
var model = new CulturesContainer
{
CurrentCulture = Thread.CurrentThread.CurrentCulture,
CurrentUICulture = Thread.CurrentThread.CurrentUICulture,
CurrentThreadId = Thread.CurrentThread.ManagedThreadId
};
Log.Write(Level.Info, "CurrentUICulture - Before Await - " +
"CurrentCulture: " +
$"{Thread.CurrentThread.CurrentCulture}, " +
"CurrentUICulture: "
${Thread.CurrentThread.CurrentUICulture} -> "+
"ThreadId: " +
$"{Thread.CurrentThread.ManagedThreadId}");
await GetAwait();
Log.Write(Level.Info, "CurrentUICulture - After Await - " +
"CurrentCulture: " +
$"{Thread.CurrentThread.CurrentCulture}, …
Run Code Online (Sandbox Code Playgroud) 尝试使用Mono for Android构建MonoDevelop时出现此错误.根据调试它不在我的代码中,所以我离开了无能为力.任何的想法?
错误MSB4185:尚未启用"System.Globalization.CultureInfo"类型上的"CurrentUICulture"函数.(MSB4185)
是否有可能在WinRT中即时更改UI文化?我发现ApplicationLanguages.PrimaryLanguageOverride = "en";
,但这仅在显示应用程序UI之前有效,而不是之后(例如我想通过设置更改UI语言).
"Windows 7区域和语言"对话框中的各种设置为CurrentCulture对象的属性提供值.但是,WPF控件似乎使用CurrentUICulture,导致完全无法尊重用户的首选项.
例如,在我的工作站上,WPF控件似乎使用了en-US的CurrentUICulture,导致它们以美国格式M/d/yyyy显示日期,而不是在"区域和语言"对话框中指定的澳大利亚格式.
在数据绑定中明确指定en-AU的文化会导致相关控件使用默认的澳大利亚格式,但它会继续忽略用户指定的格式.这很奇怪; 踩到应用程序我验证了DateTimeFormatInfo.CurrentInfo == Thread.CurrentThread.CurrentCulture.DateTimeFormat(同一个对象)和DateTimeFormatInfo.CurrentInfo.ShortDatePattern =="yyyy-MM-dd"(我设置的值,所以我可以确定用户首选项或默认值被提取).一切都如预期的那样,所以从表面上看,最重要的问题是如何说服WPF控件和数据绑定使用CurrentCulture而不是CurrentUICulture.
我们如何让WPF应用程序尊重区域和语言设置?
在Sphinxx的答案的基础上,我推翻双方 Binding类的构造函数为用户提供标准的标记更完整的兼容性.
using System.Globalization;
using System.Windows.Data;
namespace ScriptedRoutePlayback
{
public class Bind : Binding
{
public Bind()
{
ConverterCulture = CultureInfo.CurrentCulture;
}
public Bind(string path) : base(path)
{
ConverterCulture = CultureInfo.CurrentCulture;
}
}
}
Run Code Online (Sandbox Code Playgroud)
进一步的实验表明,您可以使用x:Static在标记中引用System.Globalization.CultureInfo.CurrentCulture.这在运行时是完全成功的,但在设计时是一场灾难,因为绑定编辑器一直在删除它.一个更好的解决方案是帮助类遍历窗口的DOM并修复它找到的每个Binding的ConverterCulture.
using System;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace ScriptedRoutePlayback
{
public static class DependencyHelper
{
static Attribute[] __attrsForDP = new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid) …
Run Code Online (Sandbox Code Playgroud) 在我的 WPF 应用程序中,CurrentUICulture 没有被 Windows 正确接管或错误地存储在 Windows 中。
Windows 中的区域和语言设置在我找到“Deutsch (Schweiz)”的所有地方都有。应用程序中的 CurrentUICulture 显示“Deutsch (Deutschland)”而不是“Deutsch (Schweiz)”。我已经在多台计算机上测试过它(域用户和本地用户)。
问题可能出在哪里?在 Windows 中是否有很难找到此设置的地方?
重要提示:我知道我可以在应用程序中设置文化。我不需要像这样的答案 Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-ch")
我只想了解该机制的工作原理以及它从何处获取信息。
这是我的 Windows 设置中的一些屏幕截图:
谢谢,阿德里安
我想创建一个可本地化的WPF应用程序.我按照AssemblyInfo.cs文件的注释中的说明操作:
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
Run Code Online (Sandbox Code Playgroud)
完成此操作后,我的应用程序不再启动了.我正在使用自定义App类:
namespace Namespace
{
public partial class App : Application
{
[STAThread()]
[SecurityPermission(SecurityAction.LinkDemand)]
public static void Main()
{
var app = new App();
app.InitializeComponent(); …
Run Code Online (Sandbox Code Playgroud) 所以,我有一些资源文件用于本地化.它们是可以格式化的字符串.
例如:
MyResource.resx
Title: "MyApp - Ver: {0}"
Run Code Online (Sandbox Code Playgroud)
我然后通过这样做返回它:
public String Title
{
get { return String.Format(CultureInfo.CurrentUICulture, MyResources.Title, 1); }
}
Run Code Online (Sandbox Code Playgroud)
我理解CurrentUICulture和CurrentCulture之间的区别,但是FxCop告诉我使用CurrentCulture吗?
c# cultureinfo string-formatting currentculture currentuiculture
我正在使用两种语言的多语种网站开始使用阿拉伯语和英语
我已经在IE中以及在FireFox上将语言设置为阿拉伯语(ar-ae)但它总是让我获得英语版本我无法解决此问题
网站结构
Default.aspx
en/Default.aspx
ar/Default.aspx
Run Code Online (Sandbox Code Playgroud)
问题是当我使用URL http://localhost:49831/site/Defualt.aspx
然后它工作正常并且ar/Default.aspx
如果选择阿拉伯语作为语言则将我重定向到阿拉伯语版本.
但是当使用URL时,http://localhost:49831/site/
它总是将我重定向到英文版 en/Default.aspx
我不确定我做错了什么.
我仅使用Default.aspx来检测默认的浏览器语言,然后相应地重定向
Default.aspx.cs文件的CODE
// Localization and Globalization code
protected override void InitializeCulture()
{
String lang = Request["Language"];
Session["lang"] = Helper.DetectLanguage(lang);
//Set Direction of page LTR/RTL
if (Session["lang"] == "ar-AE")
{
Session["PageDIR"] = "rtl";
}
else
{
Session["PageDIR"] = "ltr";
}
base.InitializeCulture();
}
public static String DetectLanguage(String lang)
{
String LangCode = lang;
if (!string.IsNullOrEmpty(lang))
{
lang = lang.ToLower();
}
String Lang2Char;
CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; …
Run Code Online (Sandbox Code Playgroud) 例如,我有一个双倍
double d = 4.323d;
Run Code Online (Sandbox Code Playgroud)
我想在Silverlight 4应用程序的TextBlock中显示它,但显示应该是这样的:
4.32
我无法在绑定上更改StringFormat.
唯一的例外是,如果数字是这样的:
double d2 = 4d;
Run Code Online (Sandbox Code Playgroud)
然后它应该显示
4
不是4.00
.
最糟糕的例外是它应该考虑到当前的UI文化,这意味着如果应用程序在美国部署,它应该使用a .
作为小数分隔符,而在欧洲它应该使用a ,
(而不是在英国,但你明白了......)
我可以将defaultformat设置为#.##
IF我能够更改StringFormat,但我想通过CultureInfo来实现
在我在 Win 10 下修改 PS 5.1 期间,与问题的目标完全更改当前 PowerShell 会话的语言(包括文化)相关,\n我遇到了几个相关问题。
\n与 UICulture 关联的 Windows 设置在哪里?\n我没有找到“区域和语言”控制面板的“键盘和语言”选项卡,如此处所示。
\n这可以在 PS 中持续更改吗?\n到目前为止我发现的所有内容都只保留在会话中。
\n设置设置- >时间和语言->语言-> Windows 显示语言显示“Espa\xc3\xb1ol (Espa\xc3\xb1a)”,PS 给出
\n> Get-UICulture ; [System.Threading.Thread]::CurrentThread.CurrentUICulture ; [CultureInfo]::CurrentUICulture ;\nLCID Name DisplayName\n---- ---- -----------\n1033 en-US English (United States)\n1033 en-US English (United States)\n1033 en-US English (United States)\n
Run Code Online (Sandbox Code Playgroud)\n没有任何干预更改并且在刚刚启动的会话中。
\ncurrentuiculture ×13
cultureinfo ×8
c# ×7
wpf ×4
asp.net ×2
culture ×2
localization ×2
uiculture ×2
.net ×1
android ×1
asp.net-mvc ×1
async-await ×1
mono ×1
monodevelop ×1
powershell ×1
resources ×1
silverlight ×1
windows ×1
windows-10 ×1