背水一战 Windows 10 (81) - 全球化

简介: 原文:背水一战 Windows 10 (81) - 全球化[源码下载] 背水一战 Windows 10 (81) - 全球化 作者:webabcd介绍背水一战 Windows 10 之 全球化 Demo 格式化数字 示例1、演示全球化的基本应用Localization/GlobalizationDemo.
原文: 背水一战 Windows 10 (81) - 全球化

[源码下载]


背水一战 Windows 10 (81) - 全球化



作者:webabcd


介绍
背水一战 Windows 10 之 全球化

  • Demo
  • 格式化数字



示例
1、演示全球化的基本应用
Localization/GlobalizationDemo.xaml

<Page
    x:Class="Windows10.Localization.GlobalizationDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Localization"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <TextBlock Name="lblMsg" />

        </StackPanel>
    </Grid>
</Page>

Localization/GlobalizationDemo.xaml.cs

/*
 * 演示全球化的基本应用
 * 
 * 
 * 注:本地化和全球化的区别
 * 1、全球化的产品应该适用于任何一个本地市场
 * 2、本地化通常会有 UI 的调整,语言的翻译,甚至是针对本地开发的一些特殊的功能
 * 3、一个全球化的产品做本地化时,一般只做语言翻译
 */

using System;
using Windows.Globalization;
using Windows.System.UserProfile;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Windows10.Localization
{
    public sealed partial class GlobalizationDemo : Page
    {
        public GlobalizationDemo()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 首选语言
            lblMsg.Text = "Current Languages: " + string.Join(", ", GlobalizationPreferences.Languages);
            lblMsg.Text += Environment.NewLine;
            // 首选日历(比如:GregorianCalendar 提供了世界上大多数国家/地区使用的标准日历系统)
            lblMsg.Text += "Current Calendars: " + string.Join(", ", GlobalizationPreferences.Calendars); 
            lblMsg.Text += Environment.NewLine;
            // 时钟显示(比如:24HourClock)
            lblMsg.Text += "Current Clocks: " + string.Join(", ", GlobalizationPreferences.Clocks);
            lblMsg.Text += Environment.NewLine;
            // 区域(比如:CN)
            lblMsg.Text += "Current HomeGeographicRegion: " + GlobalizationPreferences.HomeGeographicRegion;
            lblMsg.Text += Environment.NewLine;
            // 一周的第一天是周几(比如:中国是 Monday)
            lblMsg.Text += "Current WeekStartsOn: " + GlobalizationPreferences.WeekStartsOn.ToString();
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += Environment.NewLine;


            // Language - 语言对象,通过指定 BCP-47 语言标记来实例化语言对象
            Windows.Globalization.Language language = new Windows.Globalization.Language("zh-Hans-CN");
            // 判断指定的 BCP-47 语言标记的格式是否正确
            lblMsg.Text += "zh-Hans-CN IsWellFormed: " + Windows.Globalization.Language.IsWellFormed("zh-Hans-CN");
            lblMsg.Text += Environment.NewLine;
            // 语言的本地化名称
            lblMsg.Text += "zh-Hans-CN Language DisplayName: " + language.DisplayName;
            lblMsg.Text += Environment.NewLine;
            // 语言本身的名称
            lblMsg.Text += "zh-Hans-CN Language NativeName: " + language.NativeName;
            lblMsg.Text += Environment.NewLine;
            // 语言的 BCP-47 语言标记
            lblMsg.Text += "zh-Hans-CN Language LanguageTag: " + language.LanguageTag;
            lblMsg.Text += Environment.NewLine;
            // 语言的 ISO 15924 脚本代码
            lblMsg.Text += "zh-Hans-CN Language Script: " + language.Script;
            lblMsg.Text += Environment.NewLine;
            // 获取当前输入法编辑器 (IME) 的 BCP-47 语言标记
            lblMsg.Text += "zh-Hans-CN Language CurrentInputMethodLanguageTag: " + Windows.Globalization.Language.CurrentInputMethodLanguageTag;
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += Environment.NewLine;


            // GeographicRegion - 区域对象(关于 ISO 3166-1 请参见:http://zh.wikipedia.org/zh-cn/ISO_3166-1
            GeographicRegion geographicRegion = new GeographicRegion(); // 获取当前的区域对象。
            // 区域的本地化名称
            lblMsg.Text += "Current Region DisplayName: " + geographicRegion.DisplayName;
            lblMsg.Text += Environment.NewLine;
            // 区域本身的名称
            lblMsg.Text += "Current Region NativeName: " + geographicRegion.NativeName;
            lblMsg.Text += Environment.NewLine;
            // 该区域内使用的货币类型
            lblMsg.Text += "Current Region CurrenciesInUse: " + string.Join(",", geographicRegion.CurrenciesInUse);
            lblMsg.Text += Environment.NewLine;
            // 该区域的 ISO 3166-1 二位字母标识
            lblMsg.Text += "Current Region CodeTwoLetter: " + geographicRegion.CodeTwoLetter;
            lblMsg.Text += Environment.NewLine;
            // 该区域的 ISO 3166-1 三位字母标识
            lblMsg.Text += "Current Region CodeThreeLetter: " + geographicRegion.CodeThreeLetter;
            // 该区域的 ISO 3166-1 数字标识
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "Current Region CodeThreeDigit: " + geographicRegion.CodeThreeDigit;
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += Environment.NewLine;


            // Calendar - 日历对象,默认返回当前系统的默认日历
            Calendar calendarDefault = new Calendar();
            // 第一个参数:将日历转换为字符串时,优先使用的语言标识列表;第二个参数:指定日历的类型;第三个参数:指定是12小时制还是24小时制
            Calendar calendarHebrew = new Calendar(new[] { "zh-CN" }, CalendarIdentifiers.Hebrew, ClockIdentifiers.TwentyFourHour);
            lblMsg.Text += "Gregorian Day: " + calendarDefault.DayAsString(); // 公历的日期
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "Hebrew Day: " + calendarHebrew.DayAsString(); // 希伯来历的日期
            // Calendar 还有很多属性和方法,不再一一介绍,需要时查 msdn
        }
    }
}


2、演示不同语言环境下对数字的格式化
Localization/NumberFormatting.xaml

<Page
    x:Class="Windows10.Localization.NumberFormatting"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Localization"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <TextBlock Name="lblMsg" />

        </StackPanel>
    </Grid>
</Page>

Localization/NumberFormatting.xaml.cs

/*
 * 演示不同语言环境下对数字的格式化
 */

using System;
using Windows.Globalization.NumberFormatting;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Windows10.Localization
{
    public sealed partial class NumberFormatting : Page
    {
        public NumberFormatting()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 百分比格式化
            PercentFormatter percentFormatter = new PercentFormatter();
            // PercentFormatter percentFormatter = new PercentFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text = percentFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 千分比格式化
            PermilleFormatter permilleFormatter = new PermilleFormatter();
            //  PermilleFormatter permilleFormatter = new PermilleFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += permilleFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 数字格式化
            DecimalFormatter decimalFormatter = new DecimalFormatter();
            // DecimalFormatter decimalFormatter = new DecimalFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += decimalFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 货币格式化
            CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY");
            // CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY", new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += currencyFormatter.Format(3.1415926);
        }
    }
}



OK
[源码下载]

目录
相关文章
|
Windows
Windows Phone 应用程序的全球化“.NET研究”
  Windows Phone 应用程序的全球化跟Silverlight做法一样,如果大家熟悉Silverlight的全球化,可以不看此文。本文一个具体的Demo介绍wp7应用程序如何实现本地化,并在本地化的一些注意点。
992 0
|
Windows
重新想象 Windows 8 Store Apps (57) - 本地化和全球化
原文:重新想象 Windows 8 Store Apps (57) - 本地化和全球化 [源码下载] 重新想象 Windows 8 Store Apps (57) - 本地化和全球化 作者:webabcd介绍重新想象 Windows 8 Store Apps 之 本地化和全球化 本地化 - ...
874 0
|
1月前
|
网络安全 虚拟化 Windows
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题
|
2月前
|
PHP Windows
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
|
2月前
|
开发框架 .NET API
Windows Server 2022 安装IIS 报错 访问临时文件夹 C:\WINDOWS\TEMP\3C 读取/写入权限 错误: 0x80070005
Windows Server 2022 安装IIS 报错 访问临时文件夹 C:\WINDOWS\TEMP\3C 读取/写入权限 错误: 0x80070005
86 0
|
2月前
|
Linux Docker Windows
Windows——Docker拉取Windows Server镜像
Windows——Docker拉取Windows Server镜像
111 0
|
3月前
|
弹性计算 持续交付 Docker
阿里云云效产品使用合集之如何部署到阿里云服务器上的 Windows Server 上的 IIS
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
3月前
|
网络协议 Unix 网络安全
FTP服务器怎么搭建?Windows server搭建FPT服务器
FTP服务器是按照FTP协议提供文件传输服务的计算机。它用于在两台计算机间安全地传输文件,支持用户权限管理和跨平台操作。FTP使用控制连接处理命令,数据连接传输文件,有PORT和PASV模式。要搭建FTP服务器,首先在Windows Server 2008 R2上安装IIS,确保选中FTP服务。接着,创建FTP文件夹作为站点根目录,通过IIS管理器添加FTP站点,配置站点信息、身份验证和权限。测试客户端通过telnet和浏览器访问FTP服务器,确认能成功登录及浏览文件。FTP常用于文件共享和管理,可通过专用工具如FlashFXP上传下载文件。
121 0
FTP服务器怎么搭建?Windows server搭建FPT服务器
|
4月前
|
编解码 安全 网络安全
RealVNC的 VNC server在windows7系统下无法正确运行
在Windows 7上运行旧版VNC Server(如4.1.2)可能存在兼容性问题,但可通过调整配置解决。步骤包括:安装VNC Server,设置兼容性模式(选择Windows XP SP3),启动VNC Server,配置VNC连接参数。若遇到问题,检查防火墙设置,确保系统更新,并考虑升级到新版VNC Server以提高性能和兼容性。
下一篇
无影云桌面