I'm developing application which requires for me to handle multiculture and resources in Windows Phone 8.1.
Currently it loads en language if my phone language is set to english, if I change it to french or whatever it also works. What i would like to do is for a user to be able to change the language in the app while not changing the language in the phone. I would like to have a settings page when user can pick language from a list of possibilities. Save it in some storage settings and after application start to load appropriate resources.
What I can't figure out is how to load specific resources based on some settings in the storage.
Use IsolatedStorage to store the user selected language string.
When the app is loaded you can change the language to that selected by user using the
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride
Property.
Let me give you some details.
Create a class as LacalizedStrings.cs in your project.
And let's put that the resource file name is AppResources
public class LocalizedStrings
{
private static AppResources _localizedResources = new AppResources();
public AppResources LocalizedResources { get { return _localizedResources; } }
}
in your AppResources put one key as ResourceLanguage and value as en-US.
Now this value you can save in IsolatedStorage and the time of
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
or
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
you can check this value from IsolatedStorage and use it.
Hope it helps.
Related
Background
I am developing an application that needs to browse a file manager , pick an image file and display that in an Android ImageView object. The code that starts the image file picker is this one below.
private void TextView_Click(object sender, EventArgs e)
{
//show the file manager with extensions
Intent image_intent= new Intent(Intent.ActionOpenDocument);
image_intent.AddCategory(Intent.CategoryOpenable);
//set the type for image files
image_intent.SetType("image/*");
StartActivityForResult(image_intent, 899);
}
Problem
However when I try to override the OnActivityResult() method so that I can process the image data from the resulting Intent data, Visual Studio IDE does not list the method OnActivityResult, it displays the output below.
What I tried
I tried to check if there is an existing override of this method but there was none.
I also tried to change the return type of the method to see if its been embedded in another return type but couldn't find it.
Why am I unable to override the method and how can I resolve this?
Looks like I was using the wrong access specifier to access the method, am supposed to use the keyword protected override void and not public override void. I had to check with the documentation on Microsoft Docs.
Hi I created this WinForm Program. It has several Forms.
I looked for a tutorial or someting to help and found this on StackoverFlow.
How to use Localization in C#
It was really helpful but..
I created a ResourceString.de-DE.resx File and added it to the Properties Folder.
Added some Strings so i can test it. And changed the Access Modifier to Public.
Then i wanted to access the Properties Folder to Use the ResourceString.de-De.resx File.
But it doesn't get suggested.
The Code has to look like this in the end :
private void setLanguage()
{
btnSwitchLanguage.Text = Properties.ResourceString.de-DE.btnSwitchLanguage;
}
Am I missing something ?
Any Help is appreciated. :)
Thanks
You don't need to add the Strings.resx file, Your project already has the resource file Resources.resx. Therefore, you should add a new resource file with Resources.de.resx name, if required localization for the "de-DE". So, you can put into this resource file not only strings, but images, icons etc.
There is no need to change the Access Modifier to Public unless you are not going to access this resources from another assembly.
NOTE: When you are working in the Visual Studio the Visual Assist
suggestion will be the same for all languages, starting from
Properties.Resources.
You need to create a default 'ResourceString.resx' file along with al your language specific resx files. Make sure to add the same resources in all resx files. (btnSwitchLanguage, ...).
Well i found my mistake, after reading the Thread again, that i linked in my Post.
There should be a File called Strings.resx (or whatever Name you Choose), which contains the original strings.
And the File which contains another language. (German in my Example).
Should have the same name, except the language comes at the end.
Like this :
Strings.de-DE.resx
After that i just had to change my Code to :
private void btnSwitchLanguage_Click(object sender, EventArgs e)
{
if (Thread.CurrentThread.CurrentUICulture.ToString().Equals("de-DE"))
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
}
else
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
setLanguage();
}
}
private void setLanguage()
{
btnSwitchLanguage.Text = Properties.Strings.btnSwitchLanguage;
}
I have a WPF application which is localized.
When I set Format to Hindi(India) from ControlPanel -> Region -> Formats, Following lines of code in my WPF application at the beginning of launching of my WPF Application is not reading CultureInfo.CurrentCulture(hi-IN) instead it uses en-US.
Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();
Because of this, My WPF Application is not using greeting message from Resources.resx file. Instead, it is use greeting message from in Resources.en.resx
I am getting proper value in CultureInfo.CurrentCulture.
Any idea why above lines of code are not picking proper value?
The ControlPanel->Region->Formats setting doesn't apply to .resx files. It is in ControlPanel->Region->Language that you specify the default language.
What is the difference between CurrentCulture and CurrentUICulture properties of CultureInfo in .NET?
Alternatively you could specify the default language of your resources in your App class (App.xaml.cs):
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
}
}
Please refer to the following link for more information: https://social.msdn.microsoft.com/Forums/vstudio/en-US/6bfb8d13-3a86-4c10-a632-bb20c99d0535/localization-in-wpf-using-resx-files-for-different-languages?forum=wpf.
i am new to Windows store app. now i created the folder for the resource file for French[Strings -> fr-FR ->Resources.resw] and English[Strings -> en-US ->Resources.resw].
and declared the Heading1="hdFREN" and Heading1="hdENG" respectively.
now i have to call the Heading1 to the TextBlock text="".. How to declare the text in the TextBlock control???
Actually i created the resources.resw in the root folder [Strings -> fr-FR ->Resources.resw] and English[Strings -> en-US ->Resources.resw]. then i am creating manually LocalizedStrings
enter code here
public class LocalizedStrings
{
private static Resources _localizedResources = new Resources();
public Resources LocalizedResources { get { return _localizedResources; } }
}
now i can't call that Resources file. it is showing error
This is a an overview of localization, and should address most of your questions.
Quickstart: Translating UI resources (Windows Store apps using C#/VB/C++ and XAML)
I am working on a metro app which provides a change language option in app. I want that on change of language textbox input language also get change. and it should not depends on system language.
I use these codes:
First of all you must find the name of the culture language you want.
method "GetInutLanguageByName" will return the language that you requested
Then you will check whether you installed the requested language or not, if yes then return the requested language.
Then change the input language very easy...
private static InputLanguage GetInutLanguageByName(string layOut)
{
foreach (InputLanguage lng in InputLanguage.InstalledInputLanguages)
{
if (lng.Culture.DisplayName == layOut)
{
return lng;
}
}
return null;
}
private void SetKeyboardLayout(InputLanguage Layout)
{
InputLanguage.CurrentInputLanguage = Layout;
}
private void FirstNameTextBox_Enter(object sender, EventArgs e)
{
SetKeyboardLayout(GetInutLanguageByName("Persian"));
}
Firstly, you need to make sure that the language you want is installed in OS, and it is in the list of INSTALLED INPUT LANGUAGES (check the language bar in control panel under Language and Regional Settings).. If its not in language bar, add it..
e.g. you want to change app language to "FRENCH".. you would need to create a new resource file for every language you want to change in app, and then change the current thread's Culture Property..
Are you familiar with resources file (.resx) and Culture Info Class??