Windows 8 Store Apps學習(57) 本地化和全球化

來源:互聯網
上載者:User

介紹

重新想象 Windows 8 Store Apps 之 本地化和全球化

本地化 - Demo

本地化 - 改變語言

全球化 - Demo

全球化 - 格式化數字

樣本

1、示範本地化的基本應用

Localization/LocalizationDemo.xaml

<Page    x:Class="XamlDemo.Localization.LocalizationDemo"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:XamlDemo.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="120 0 0 0">                            <TextBlock FontSize="14.667">                <Run>本地化資源檔,以下舉例說明:</Run>                <LineBreak />                <Run>1、在 en 目錄下的是英文資源檔,在 zh-CN 目錄下的是簡體中文(zh 代表語言,CN 代表國家或地區)資源檔</Run>                <LineBreak />                <Run>2、Resources.lang-en.resw 代表英文資源檔,Resources.lang-zh-CN.resw 代表簡體中文資源檔</Run>                <LineBreak />                <Run>3、圖片資源的本地化可以參照以上命名規則,同時可與 scale 和 high contrast 相結合</Run>                <LineBreak />                <Run>4、Package.appxmanifest 中引用的字串也支援本地化,引用方式:ms-resource:Hello 或 ms-resource:///Resources/Hello</Run>                <LineBreak />                <Run>5、Tile 和 Toast 中引用的字串也支援本地化,引用方式:ms-resource:Hello 或 ms-resource:///Resources/Hello</Run>                <LineBreak />                <Run>6、當無法找到某語言對應的資源時,系統會自動使用 Package.appxmanifest 中設定的預設語言所對應的資源</Run>            </TextBlock>                <!--                通過 x:Uid 本地化控制項的各個屬性,請參看資源檔中的 HelloTextBlock.FontSize 和 HelloTextBlock.Text            -->            <TextBlock x:Uid="HelloTextBlock" Margin="0 10 0 0" />                <!--                code - behind 方式擷取本地化資源            -->            <TextBlock x:Name="lblMsg" FontSize="14.667" Margin="0 10 0 0" />                <!--                圖片的本地化            -->            <Image Source="/Localization/Logo.png" Width="200" Height="100" Margin="0 10 0 0" HorizontalAlignment="Left" />                        </StackPanel>    </Grid></Page>

Localization/LocalizationDemo.xaml.cs

/* * 示範本地化的基本應用 *  * 另: * Visual Studio 2012 的多語言應用程式工具包請參見:http://msdn.microsoft.com/zh-cn/windows/apps/hh848309 */    using Windows.ApplicationModel.Resources;using Windows.ApplicationModel.Resources.Core;using Windows.UI.Xaml.Controls;using Windows.UI.Xaml.Navigation;    namespace XamlDemo.Localization{    public sealed partial class LocalizationDemo : Page    {        public LocalizationDemo()        {            this.InitializeComponent();         }            protected override void OnNavigatedTo(NavigationEventArgs e)        {            /*             * ResourceLoader resourceLoader = new ResourceLoader(); - 擷取預設的 ResourceLoader(Resources.resw 中的資源)             * ResourceLoader resourceLoader = new ResourceLoader("MyResources"); - 擷取指定的 ResourceLoader(MyResources.resw 中的資源)             * ResourceLoader resourceLoader = new ResourceLoader("ClassLibrary/MyResources"); - 擷取指定類庫的指定的 ResourceLoader(ClassLibrary 類庫中的 MyResources.resw 中的資源)             */                // 擷取預設的 ResourceLoader(即 Resources.resw 中的資源)            ResourceLoader resourceLoader = new ResourceLoader();                // 通過資源標識,擷取指定的資源            lblMsg.Text = resourceLoader.GetString("Hello");        }    }}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.