[源码下载]

背水一战 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 10 (81) - 全球化的更多相关文章

  1. 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件

    [源码下载] 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件 作者 ...

  2. 背水一战 Windows 10 (13) - 绘图: Stroke, Brush

    [源码下载] 背水一战 Windows 10 (13) - 绘图: Stroke, Brush 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Stroke - 笔划 Brush ...

  3. 背水一战 Windows 10 (12) - 绘图: Shape, Path

    [源码下载] 背水一战 Windows 10 (12) - 绘图: Shape, Path 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Shape - 图形 Path - 路径 ...

  4. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...

  5. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  6. 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...

  7. 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing

    [源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...

  8. 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...

  9. 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox

    [源码下载] 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) Sel ...

随机推荐

  1. 201772020113李清华《面向对象程序设计(java)》第八周学习总结

    实验六 接口的定义与使用 实验时间 2018-10-18 1.实验目的与要求 (1) 掌握接口定义方法: (2) 掌握实现接口类的定义要求: (3) 掌握实现了接口类的使用要求: (4) 掌握程序回调 ...

  2. awk选取制定行数,条件判断等

    awk '{if(NR%5==0){print}}' your_file 取出可以被5整除的数awk '{if(NR<=300){print}}' your_file 取出行数小于300的数据a ...

  3. django admin 设置(转载https://www.cnblogs.com/wumingxiaoyao/p/6928297.html)

    Django admin 一些有用的设置   Django自带的后台管理是Django明显特色之一,可以让我们快速便捷管理数据.后台管理可以在各个app的admin.py文件中进行控制.以下是我最近摸 ...

  4. 学习node.js 第2篇 介绍node.js 安装

    Node.js - 环境安装配置 如果愿意安装设置Node.js环境,需要计算机上提供以下两个软件: 一.文本编辑器 二.Node.js二进制安装包 文本编辑器 这将用来编写程序代码. 一些编辑器包括 ...

  5. sys模块的介绍

    sys.argv           命令行参数List,第一个元素是程序本身路径 sys.exit(n)        退出程序,正常退出时exit(0) sys.version        获取 ...

  6. java 流转换BASE64的一些问题

    java 转换BASE64过程中,出现很多结尾为空的问题!暂时不清楚为什么会这样- ``` java //根据url地址转换成BASE64 public static String getURLIma ...

  7. Zabbix Agent 源码编译安装

    简介: 单独整理一下 Zabbix Agent . 1.安装包选择 下载地址:http://www.zabbix.com/download.php 这里有两种源码包,一种是安装 Zabbix Serv ...

  8. 关于Encode in UTF-8 without BOM

    定义BOM(Byte Order Mark),字节顺序标记,出现在文本文件头部,Unicode编码标准中用于标识文件是采用哪种格式的编码.它的编码是FEFF. 说明 在 UTF-8 文件中放置 BOM ...

  9. django内置分页功能扩展

    实现自定制页码数类型class myPaginator(Paginator): def __init__(self,curr_page,per_page_num,*args,**kwargs): se ...

  10. MFC笔记6

    1.MFC文件的读写操作 写操作 创建一个编辑框(IDC_INFOR_EDIT1),在里面输入信息,创建一个按钮(IDC_BUTTON),点击按钮会触发(OnBnClickedButton2()函数) ...