I have just completed my new Windows Phone application. Now I want to add it to the store. My problem is, the app is translated into 34 languages and I have to provide screens for each of theese languages. Whenever I want to change the Culture of my Phone, I have to restart it - it takes too much time. My other idea was to change the culture of a running thread in the code but I could not find a working solution. Can you help me with this? I dont want to spend two days on doing screens for the store. o you have any other idea I could achieve this or could you provide some code that works on WP7 which changes the culture?
You can use the following code to change current culture:
CultureInfo currentCulture = new CultureInfo("Culture_Code");
Thread.CurrentThread.CurrentUICulture = currentCulture ;
You can change culture, but you can't force UI to update it automatically. So, you should write some code to change controls localization at runtime. Basically, there will be the one function that updates controls with selected Culture.
Related
I have two different language i.e English and German in my web app and user can change the language in application through a select box. Initially i am getting preferred language from the back-end and i am setting locale of the core as follows.
sap.ui.getCore().getConfiguration().setLanguage("//according to whatever is coming from back-end")
Now lets say initial language is English, if user open a control i.e sap.m.datepicker, calendar is being displayed in English. If user changes the language to German from the application i am again changing the language in the core as shown below:
sap.ui.getCore().getConfiguration().setLanguage("de-DE")
Now if user opens that same datepicker, it is being displayed in English instead of German and if user opens some another control or datepicker it is being rendered in German.
Page is not getting refreshed while changing the language in app.
Please suggest me a solution to dynamically change the locale of the controls.
Maybe my answer here helps a little.
The problem is that in many cases, maybe even in most cases, the standard UI5 controls detect the language only once when they get loaded. Very often, the control developers did not implement a "dynamic change" of the language. If you check the link I mentioned above you will see that there are ways to react on language changes, but very often this is not implemented for whatever reason.
However, I'm afraid to tell you that in your case the standard control might not support dynamic language changes out of the box (but I did not check the code). Also, it seems that the UI5 guys at SAP do not consider this as a bug (see this github issue). Such a pity...
I would suggest you use sap.ui.core.Core.attachLocalizationChanged(fnFunction, oListener) and add this to the onInit function of your controller.
From this, in your fnFunction rebuild the controls where you require the locale changes to be dynamic.
example:
onInit: function(oEvent) {
sap.ui.getCore().attachLocalizationChanged(this._handleLocalizationChanged, this);
},
_handleLocalizationChanged: function() {
// ... Some logic to re-build / set locale for the dynamic controls.
}
This is my interpretation of what should be done based on the information in the api
When I change the phone language settings on Windows Phone to a culture that is not supported by my app, it will fall back to the neutral language in the app. It does this even if there is a related culture so if I e.g choose es-US, it falls back to the neutral (en-GB in my case). Android and iOS phones, however, will choose es-ES instead and this behavior I want to mimic in my Windows Phone app.
The solution I use is to hard code supported cultures, get the selected culture, and then set the UI culture to es-ES in the case es-US is chosen.
Is there a better, less cumbersome, way?
This is because you support specifically es-ES culture, so when switch to es-US, there isn't a culture compatible and the app switch to the neutral one, en-GB. If you want to use "es" culture whenever the user have a "es-" culture, you need to support the "es" culture, without country code in it. this way, every time a user had a "es-" culture, your app use the "es" country independent culture. for this you need:
Support Spanish culture in your project (without country specific variant)
name your resource file this way: resourcefilename.es.resx
Hope this helps you.
Is there a way to change the current language to another one at runtime ?
For example: be able to switch when a button is clicked or when starting the app, get the user language and switch.
How to tell the plugin to check the user language at startup ?
Thanks in advance for your help.
Is there a way to change the current language to another one at runtime ?
yes, call builder.LoadResources(whichLanguage) on your MvxTextProviderBuilder.cs
For example: be able to switch when a button is clicked
The UI framework isn't really setup to perform switching live. When you switch between languages then the new JSON resource files will all be loaded OK - but existing displayed text will not be updated. This is a bit like most mobile operating systems - if you want to switch language you often need to reboot!
If you wanted to add dynamic switching then you'd have to find a way to tell the UI to completely refresh all text - I suspect this wouldn't be hard to do, but it might require some manual coding on every page/View which has already been created and displayed :/
or when starting the app, get the user language and switch.
This is a much more straight-forward way to do i18n. It's normally OK because MvvmCross mainly targets phones - and phones are normally single user devices which don't switch languages very often.
You could, for example, use some variable (e.g. System.Globalization.CultureInfo.CurrentUICulture) to work out the best language to display.
Or you detect on load whether the user has picked a language yet - if they have, then show HomeViewModel - if they haven't then show a LanguagePickerViewModel - this is what we did in StarWarsKinect - the StartNavigationObject is a perfect place for this sort of logic!
How to tell the plugin to check the user language at startup ?
Currently, you'll have to code this logic as part of your app startup.
I'd definitely be open to providing an improved plugin on this - perhaps with a demo!
If you are looking at i18n, then one alternative implementation to consider is Vernacular - the team at Rdio have a very good offering for Mono and MS platforms - https://github.com/rdio/vernacular
I've got few questions about localization apps in Windows 8.
Is there a way to automatic bind translations to UI element apart from element type? Currently I must provide string with id like "welcomeText.text" for textblock and "welcomeButton.Content" for button. It makes creating files with translations more complicated.
Does Windows 8 has similar solutions to this -> http://developer.android.com/guide/topics/resources/string-resource.html#Plurals ?
Thank you in advance,
Chris
Unfortunately I think the answer to both questions is no.
As for question 1:
If you use the standard way of localizing Windows 8 apps you will have to specify the property, which is not great but understandable; how else would the platform know to what property it should bind? Perhaps I want to bind the Header property instead of the Content property.
There is no way for the platform to determine what I want unless I specify it.
I'm using MVVM Light in my Windows Phone 7 application. The application is to be used in English and Spanish. Users can select a different language during runtime. I'm localizing the application using resource files. I've already been able to make the localization works, but only when I change the language from Settings. In the main page, I have a list for users to select the language during runtime, I'm setting the selected language to Thread.CurrentThread.CurrentCulture, but the text strings in the interface don't get updated. I have a set of properties in the ViewModel that I'm binding to the View to set the labels of the control, but something is missing. I've been reading that I need to implement the INotifyPropertyChanged in the ViewModel to make this works, but I don't know how to exactly do that nor if there is a different better way to implement this case using MVVM Light. Could anybody help me here please?
Hum, I wrote a blog post about it sometimes ago ( http://wp7wonders.wordpress.com/2010/10/17/localize-a-windows-phone-7-application/ - read the comments too!). The main point is that you have an object between the resource files and your viewmodels which allow to change the dynamically the language.