In a WPF application, for a localizable text resource such as an error message, should I be using a .resx file or a ResourceDictionary. If the answer is either/or what factors would help me decide which to use?
Using .resx files - with the name of the culture in the filename - is probably the easiest way to go. The loading of the appropriate resources is handled for you.
So you'd have "ResourceFile.resx" as your default and then "ResourceFile.en-GB.resx", "ResourceFile.fr-FR.resx" etc for your localised strings.
You only need to put those strings that actually need localisation in the language files. If the string's not present in the culture specific file it falls back to the default file.
Related
I am building a wpf user control to provide navigation facilities for database records.
The control is provided with a set of default images (as illustrated above) which the end user can change is they so wish. In addition the end user can choose to dispense with images altogether. In the event that they select that option (for either one or all of the buttons that comprise the control) I have provided some default fallback text.
This text can also be overwritten by the end user if they so wish, but the default text at least provides them with some basic text that essentially conveys what the button does and saves them having to add text every time they use the control (default tooltip text is also provided).
Now if you happen to speak English, or your intended target audience is English this should work, but it doesn't really cater as is for languages other than English. This I would now like to change.
What reading I've done on the subject of multi-lingual resources and wpf seems to assume that one is talking about the overall application rather than a standalone user control that might be used in different language environments.
I had a talk with a creator of controls who said that making this multilingual would probably involve building several copies of the control for each intended language.
In the light of this I have two questions. Was the gentleman I spoke to correct, should I in fact build multiple copies of this for each language, of is there a way to have multi-language resources within the same copy of the user control?
If the latter is possible what is the correct way to go about achieving this. We will be dealing in total with default texts for eleven buttons (which I will need to be able to refer to in code within the control incidentally) and default texts for thirteen tooltips (which again will need to be able to be referred to within the code of the control).
Take a look on WPF localization extension.
Here's a pretty good documentation for it: link.
You can define your controls' localizable properties, which store their localized values in the satellite resource assemblies.
In your xaml code, define the localized properties with xaml extensions syntax:
<Button Content="{lex:Loc Test}" />
Then, create resource files for each culture your application will support and give them the same name as the main assembly plus the general or specific culture code (e.g. en-US, de, de-AT, ...) before the .resx ending yielding: AssemblyName.CultureCode.resx.
Now, populate the resource files with your localized properties key/value pairs and build the project.
You're done!
I've looked on MSDN, and I am having trouble finding which file types (extensions) can be displayed in a RichTextBox in Winforms.
I have written an app that allows the user to display files from a specific folder based on the user's choice of file extensions. For example only display .txt and .html and ignore anything else.
Therefore, I need an exhaustive list of the extensions that wiil render properly so that I can populate a list for the user to choose from.
I don't suppose it's relevant but I'm using C#.
Any help is appreciated. thank you.
From MSDN's documentation, it appears that the RichTextBox is only intended to open .rtf files, but can also open plain text (.txt) ASCII and Unicode files using the LoadFile method with the RichTextBoxStreamType argument.
Sources:
RichTextBox.LoadFile Method
RichTextBoxStreamType Enumeration
I have an composite application which has a Shell window and has some modules, each module is loaded on to the shell using MEF (Microsfot Prism). Shell Itself has a resource file default(Resource.resx) and for other languages(like Resource.ar-SA.resx) too to support Localilzation.
For Xaml : I had used x:Static Resource.KeyName
In c# Code : I had used GetString(keyName, culture) to get the required string.
To support Localization, I have added a line of code which gets the current culture of the system and loads the required Resx File.
For Setting the Current Culture.
Resource.Culture =
new System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.Name);
in App.Xaml.cs
All these work Completely fine.
Similarly, each module which is loaded using MEF has Resource files as mentioned above. But in case of Modules, resource Key defined in the Xaml for a specific language file is not working. Its always getting the values from the Default (Resource.Resx) file. But any key used in the code using ResourceManager class works fine.
I ended up keeping all my resources in an "Infrastructure" project so all the resources are loaded from one place, it just made it simpler.
My xaml bindings look like this
Get the refrence to your resx class.
xmlns:resources="clr-namespace:Infrastructure.resources;assembly=Infrastructure"
now get the text
Content="{x:Static resources:Resources.Activity_Regarding}"
You might be doing this already but I cant see. You would want to make sure the namespace matches for the resx you want to use. So your modules namespace.
I am using silver light 4 and for XAML text blocks binding i want to use multiple resource file but unable to implement it. one link is supporting the concept of not having multiple resource file of same language at runtime dynamically
http://msdn.microsoft.com/en-us/magazine/gg650657.aspx[^]
i m using the following code for binding a text block using 1 resource file
where ResourceKey is the key defined at App.xaml and CNICNumberTextBlock is the name defined in resource file
App.xaml key defining:
Kindly help me to make use of multiple resource file at run time
I have came across some links which might be useful to u..
Localisation - Michael Snow
Jeff Prosise Blog
Subject says it all. I have Resources.en-US.resx, Resources.de-DE.resx, etc. I don't ever want the basic Resources.resx file to be referenced. If someone passes me a language that I don't have a resx for I want it to drop back and use Resources.en-US.resx. Anyone?
Use the NeutralResourcesLanguageAttribute:
[assembly: NeutralResourcesLanguageAttribute("en-US" , UltimateResourceFallbackLocation.Satellite)]