From: Gustavo Martin Date: Sun, 22 Jun 2014 07:05:17 +0000 (+0200) Subject: WeahterInformation WP8: X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5478f804e5a7c6d97fc8b46794596308b548ba0f;p=CSharpForFun%2F.git WeahterInformation WP8: 1. Settings page. 2. Default language english. 3. Using MAT (Multilingual App Toolkit) --- diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml index 895af5e..d6d3d13 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml @@ -1,12 +1,18 @@  + xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ViewModels="clr-namespace:WeatherInformation.ViewModels" mc:Ignorable="d" + x:Class="WeatherInformation.App"> + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs index 7b65355..754820d 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs @@ -6,6 +6,8 @@ using System.Windows.Markup; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; +using System.Threading; +using System.Globalization; using WeatherInformation.Resources; using WeatherInformation.ViewModels; @@ -13,6 +15,11 @@ namespace WeatherInformation { public partial class App : Application { + // Locale to force CurrentCulture to in InitializeLanguage(). + // Use "qps-PLOC" to deploy pseudolocalized strings. + // Use "" to let user Phone Language selection determine locale. + // public static String appForceCulture = "qps-PLOC"; + public static String appForceCulture = "en"; private static MainViewModel viewModel = null; private static SettingsViewModel _settingsViewModel = null; @@ -222,6 +229,15 @@ namespace WeatherInformation { try { + // Force CurrentUICulture to locale defined by appForceCulture. + // An empty string allows the user's Phone Language setting to + // determine the locale. + //if (Debugger.IsAttached && String.IsNullOrWhiteSpace(appForceCulture) == false) + //{ + // Thread.CurrentThread.CurrentCulture = new CultureInfo(appForceCulture); + // Thread.CurrentThread.CurrentUICulture = new CultureInfo(appForceCulture); + //} + // Establecer la fuente para que coincida con el idioma definido por // Cadena de recursos ResourceLanguage para cada idioma admitido. // diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs index 1181882..e310a8c 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/AssemblyInfo.cs @@ -34,4 +34,4 @@ using System.Resources; // mediante el carácter '*', como se muestra a continuación: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: NeutralResourcesLanguageAttribute("es-ES")] +[assembly: NeutralResourcesLanguageAttribute("en")] diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml index 6f0fb18..46b8cd5 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Properties/WMAppManifest.xml @@ -1,8 +1,9 @@  - + - + + Assets\ApplicationIcon.png @@ -25,16 +26,11 @@ 0 Assets\Tiles\FlipCycleTileMedium.png WeatherInformation - - - - - - - - - - + + + + + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs index 0600eb5..68019f7 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -61,7 +61,7 @@ namespace WeatherInformation.Resources { } /// - /// Busca una cadena traducida similar a agregar. + /// Busca una cadena traducida similar a add. /// public static string AppBarButtonText { get { @@ -70,7 +70,7 @@ namespace WeatherInformation.Resources { } /// - /// Busca una cadena traducida similar a Elemento de menú. + /// Busca una cadena traducida similar a Menu item. /// public static string AppBarMenuItemText { get { @@ -79,7 +79,7 @@ namespace WeatherInformation.Resources { } /// - /// Busca una cadena traducida similar a MI APLICACIÓN. + /// Busca una cadena traducida similar a MY APPLICATION. /// public static string ApplicationTitle { get { @@ -88,47 +88,74 @@ namespace WeatherInformation.Resources { } /// - /// Busca una cadena traducida similar a Language. + /// Busca una cadena traducida similar a LeftToRight. /// - public static string LanguageSettingsText { + public static string ResourceFlowDirection { get { - return ResourceManager.GetString("LanguageSettingsText", resourceCulture); + return ResourceManager.GetString("ResourceFlowDirection", resourceCulture); } } /// - /// Busca una cadena traducida similar a LeftToRight. + /// Busca una cadena traducida similar a en. /// - public static string ResourceFlowDirection { + public static string ResourceLanguage { get { - return ResourceManager.GetString("ResourceFlowDirection", resourceCulture); + return ResourceManager.GetString("ResourceLanguage", resourceCulture); } } /// - /// Busca una cadena traducida similar a es-ES. + /// Busca una cadena traducida similar a Language. /// - public static string ResourceLanguage { + public static string SettingsLanguageHeader { get { - return ResourceManager.GetString("ResourceLanguage", resourceCulture); + return ResourceManager.GetString("SettingsLanguageHeader", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a english. + /// + public static string SettingsLanguageSelectionEnglish { + get { + return ResourceManager.GetString("SettingsLanguageSelectionEnglish", resourceCulture); } } /// - /// Busca una cadena traducida similar a Valor de propiedad en tiempo de ejecución de ejemplo. + /// Busca una cadena traducida similar a spanish. /// - public static string SampleProperty { + public static string SettingsLanguageSelectionSpanish { get { - return ResourceManager.GetString("SampleProperty", resourceCulture); + return ResourceManager.GetString("SettingsLanguageSelectionSpanish", resourceCulture); } } /// /// Busca una cadena traducida similar a Temperature units. /// - public static string TemperatureSettingsText { + public static string SettingsTemperatureUnitsHeader { + get { + return ResourceManager.GetString("SettingsTemperatureUnitsHeader", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a celsius. + /// + public static string SettingsTemperatureUnitsSelectionCentigrade { + get { + return ResourceManager.GetString("SettingsTemperatureUnitsSelectionCentigrade", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a fahrenheit. + /// + public static string SettingsTemperatureUnitsSelectionFahrenheit { get { - return ResourceManager.GetString("TemperatureSettingsText", resourceCulture); + return ResourceManager.GetString("SettingsTemperatureUnitsSelectionFahrenheit", resourceCulture); } } } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx new file mode 100644 index 0000000..621209a --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + LeftToRight + Controls the FlowDirection for all elements in the RootFrame. Set to the traditional direction of this resource file's language + + + es + Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. + + + + + + + + + + +MI APLICACIÓNAgregarElemento de menúIdiomaText in settings pageUnidades de temperaturaText in settings pageinglésSettings page, select English languageespañolSettings page, select Spanish languagecelsiusSettings page, select tempereature units centigradefahrenheitSettings page, select temperature units fahrenheit \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf new file mode 100644 index 0000000..6f829c2 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf @@ -0,0 +1,64 @@ + + + +
+ +
+ + + + LeftToRight + LeftToRight + Controls the FlowDirection for all elements in the RootFrame. Set to the traditional direction of this resource file's language + + + en + es + Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. + + + MY APPLICATION + MI APLICACIÓN + + + add + Agregar + + + Menu item + Elemento de menú + + + Language + Idioma + Text in settings page + + + Temperature units + Unidades de temperatura + Text in settings page + + + english + inglés + Settings page, select English language + + + spanish + español + Settings page, select Spanish language + + + celsius + celsius + Settings page, select tempereature units centigrade + + + fahrenheit + fahrenheit + Settings page, select temperature units fahrenheit + + + +
+
\ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.resx new file mode 100644 index 0000000..a363470 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.resx @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + LeftToRight + Controls the FlowDirection for all elements in the RootFrame. Set to the traditional direction of this resource file's language + + + qps-ploc + Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. + + + [1BD7D][!!_МĮ ÀРĽÌĆÃČÌÓŇ_!!] + + + [C3F82][!!_àġřéģàŕ_!!] + + + [01F8F][!!_Êĺèmèиţô ðé мèйú_!!] + + + [D9E46][!!_Ļàйģûáğè_!!] + Text in settings page + + + [27946][!!_Ţêmþêŗáτúřê ûиìтş_!!] + Text in settings page + + + [6390E][!!_įиģľéş_!!] + Settings page, select English language + + + [3FC2A][!!_éŝрáñóľ_!!] + Settings page, select Spanish language + + + [EFA86][!!_ćęηťíğŕãďõ_!!] + Settings page, select tempereature units centigrade + + + [9AF14][!!_ƒáĥřêηĥęîţ_!!] + Settings page, select temperature units fahrenheit + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf new file mode 100644 index 0000000..807e3b2 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf @@ -0,0 +1,64 @@ + + + +
+ +
+ + + + LeftToRight + LeftToRight + Controls the FlowDirection for all elements in the RootFrame. Set to the traditional direction of this resource file's language + + + en + qps-ploc + Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. + + + MY APPLICATION + [1BD7D][!!_МĮ ÀРĽÌĆÃČÌÓŇ_!!] + + + add + [C3F82][!!_àġřéģàŕ_!!] + + + Menu item + [01F8F][!!_Êĺèmèиţô ðé мèйú_!!] + + + Temperature units + [27946][!!_Ţêmþêŗáτúřê ûиìтş_!!] + Text in settings page + + + spanish + [3FC2A][!!_éŝрáñóľ_!!] + Settings page, select Spanish language + + + fahrenheit + [9AF14][!!_ƒáĥřêηĥęîţ_!!] + Settings page, select temperature units fahrenheit + + + celsius + [EFA86][!!_ćęηťíğŕãďõ_!!] + Settings page, select tempereature units centigrade + + + english + [6390E][!!_įиģľéş_!!] + Settings page, select English language + + + Language + [D9E46][!!_Ļàйģûáğè_!!] + Text in settings page + + + +
+
\ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx index 10bd5a6..8adccab 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -122,27 +122,40 @@ Controls the FlowDirection for all elements in the RootFrame. Set to the traditional direction of this resource file's language - es-ES + en Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. - MI APLICACIÓN - - - Valor de propiedad en tiempo de ejecución de ejemplo + MY APPLICATION - agregar + add - Elemento de menú + Menu item - + Language Text in settings page - + Temperature units Text in settings page + + english + Settings page, select English language + + + spanish + Settings page, select Spanish language + + + celsius + Settings page, select tempereature units centigrade + + + fahrenheit + Settings page, select temperature units fahrenheit + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml index 4c4241e..f284267 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml @@ -1,8 +1,7 @@  + xmlns:vm="clr-namespace:WeatherInformation.ViewModels"> diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SettingsViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SettingsViewModelSampleData.xaml deleted file mode 100644 index 9e6fa96..0000000 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SettingsViewModelSampleData.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml index 599185a..53c373e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml @@ -1,5 +1,4 @@  + - - - - - - - - - - + - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - + + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml.cs index 61a8cb7..743aa4f 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml.cs @@ -9,6 +9,7 @@ using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; using WeatherInformation.ViewModels; using System.IO.IsolatedStorage; +using System.Collections; namespace WeatherInformation { @@ -29,9 +30,14 @@ namespace WeatherInformation protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!App.SettingsViewModel.IsDataLoaded) + } + + private void TemperatureUnitsSelection_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + IList units = e.AddedItems; + if (units.Count > 0) { - App.SettingsViewModel.LoadData(); + var selectedUnit = units.Cast().First(); } } } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs index d801a70..2b0e1b8 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs @@ -73,17 +73,6 @@ namespace WeatherInformation.ViewModels } } - /// - /// Propiedad de ejemplo que devuelve una cadena traducida - /// - public string LocalizedSampleProperty - { - get - { - return AppResources.SampleProperty; - } - } - public bool IsDataLoaded { get; diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SettingsViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SettingsViewModel.cs index 6e82502..c960820 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SettingsViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SettingsViewModel.cs @@ -2,44 +2,136 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.IO.IsolatedStorage; using System.Linq; using System.Text; using System.Threading.Tasks; +using WeatherInformation.Resources; namespace WeatherInformation.ViewModels { public class SettingsViewModel : INotifyPropertyChanged { + // Settings + private IsolatedStorageSettings settings; + + // The key names of settings + private const string _languageSelectionSettingKeyName = "LanguageSelection"; + private const string _temperatureUnitsSelectionSettingKeyName = "TemperatureUnitsSelection"; + + // The default value of ListPicker settings + private const int _listPickerSettingDefault = 0; + public SettingsViewModel() { - this.TemperatureUnitsSelection = new List(); - this.LanguageSelection = new List(); + // You need to add a check to DesignerProperties.IsInDesignTool to that code since accessing + // IsolatedStorageSettings in Visual Studio or Expression Blend is invalid. + // see: http://stackoverflow.com/questions/7294461/unable-to-determine-application-identity-of-the-caller + if (!System.ComponentModel.DesignerProperties.IsInDesignTool) + { + // Get the settings for this application. + settings = IsolatedStorageSettings.ApplicationSettings; + } } - public List TemperatureUnitsSelection { get; private set; } - public List LanguageSelection { get; private set; } + /// + /// Property to get and set language selection Setting Key. + /// + public int LanguageSelectionSetting + { + get + { + return GetValueOrDefault(_languageSelectionSettingKeyName, _listPickerSettingDefault); + } + set + { + if (AddOrUpdateValue(_languageSelectionSettingKeyName, value)) + { + Save(); + } + } + } - public bool IsDataLoaded + /// + /// Property to get and set temperature units selection Setting Key. + /// + public int TemperaruteUnitsSelectionSetting { - get; - private set; + get + { + return GetValueOrDefault(_temperatureUnitsSelectionSettingKeyName, _listPickerSettingDefault); + } + set + { + if (AddOrUpdateValue(_temperatureUnitsSelectionSettingKeyName, value)) + { + Save(); + } + } } /// - /// Crear y agregar unos pocos objetos a la colección Items. + /// Get the current value of the setting, or if it is not found, set the + /// setting to the default value. /// - public void LoadData() + /// + /// + /// + /// + private T GetValueOrDefault(string Key, T defaultValue) { - // TODO: How to do the same using StaticResources? :/ What the translator should do with this :( - // There must be some way to refernce static resources from here or something like that, otherwise - // the translator is going to complain A LOT! - TemperatureUnitsSelection.Add("fahrenheit"); - TemperatureUnitsSelection.Add("centigrade"); + T value; - LanguageSelection.Add("english"); - LanguageSelection.Add("spanish"); + // If the key exists, retrieve the value. + if (settings.Contains(Key)) + { + value = (T)settings[Key]; + } + // Otherwise, use the default value. + else + { + value = defaultValue; + } + return value; + } + + /// + /// Update a setting value for application. If the setting does not + /// exist, then add the setting. + /// + /// + /// + /// + private bool AddOrUpdateValue(string Key, Object value) + { + bool valueChanged = false; - this.IsDataLoaded = true; + // If the key exists + if (settings.Contains(Key)) + { + // If the value has changed + if (settings[Key] != value) + { + // Store the new value + settings[Key] = value; + valueChanged = true; + } + } + // Otherwise create the key. + else + { + settings.Add(Key, value); + valueChanged = true; + } + return valueChanged; + } + + /// + /// Save the settings. + /// + private void Save() + { + settings.Save(); } public event PropertyChangedEventHandler PropertyChanged; diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj index 0b14d44..4d7bef3 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj +++ b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj @@ -15,8 +15,7 @@ v8.0 $(TargetFrameworkVersion) true - - + es;qps-ploc true true WeatherInformation_$(Configuration)_$(Platform).xap @@ -90,6 +89,9 @@ prompt 4 + + 3.0 + App.xaml @@ -147,10 +149,6 @@ Designer MSBuild:Compile - - MSBuild:Compile - Designer - Designer MSBuild:Compile @@ -193,6 +191,18 @@ + + True + True + AppResources.es.xlf + es + + + True + True + AppResources.qps-ploc.xlf + qps-ploc + PublicResXFileCodeGenerator AppResources.Designer.cs @@ -207,8 +217,19 @@ ..\packages\Newtonsoft.Json.6.0.3\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll + + + XliffResxGenerator + AppResources.es.resx + + + XliffResxGenerator + AppResources.qps-ploc.resx + + +