MVC 4 Resource files and language dropdown - c#

I've implemented multi language support following this blog post http://geekswithblogs.net/shaunxu/archive/2010/05/06/localization-in-asp.net-mvc-ndash-3-days-investigation-1-day.aspx
Only some of the pages are in different languages, so I'm trying to create a html helper to show a dropdown to select the language they want. I want to make this html helper bit intelligent and implement it so that it will show the different languages if it's available when I provide it with a resource type.
Say, I have sample.resx, sample.ko.resx, sample.zh.resx and say their namespace is Resources.Contacts . Is it possible to find out different language resource files of a given type, namespace or whatever at runtime?

possible duplicate because it has been answered here already:
Programmatic way to get all the available languages (in satellite assemblies)
There are certain workarounds to figure out if the languages are available. You'll either have to check if the resource supports the culture, or, if check the folders within your bin directory (for each language, there might be a folder with the name of the culture).

Related

Net Core 2 / Razor - theming(views, not css only)

I am looking for solution which would allow me to serve different templates depends on what is set in session (middleware will set it based on the domain).
What I al looking for is that when the theme is set up, when some view suppose to be rendered, mvc would render the view from particular theme.
How can I do that with net core 2,mvc and razor? It would be great if adding theme wouldn't require recompilation (e.g. similar to Wordpress - upload zip file with all required files).
I really have no idea where to start...
I was trying to Google some solutions but I found only one which is outdated totally.
Basically, you just need to customize the list of directories that Razor searches for views. By default, those are Views\{controller} and Views\Shared. You just need to make it so those are instead (or maybe as well as, to have fallback to a "base" theme if a particular theme chooses not to provide a view) {theme}\Views\{controller} and {theme}\Views\Shared, or something similar.
Unfortunately, the documentation doesn't provide much support here. All you get is:
You can customize the default convention for how views are located within the app by using a custom IViewLocationExpander.
As the name implies, that's an interface that Razor uses to get a list of locations to search for views in. In other words, you'd simply need to create your own implementation and then inject that. Something like LanguageViewLocationExpander should give you an idea of what you need to do, since the basic principle at play is the same. It's used for localization and provides the ability to have views nested under language specific-folders.

Localization of strings which is inside a plugin dll C# wpf

I am creating a wpf application which contains several self contained plugin dlls which are accessed by my main application. Is there any way to provide localization support such that all the localized strings comes from inside the dll?
Example:
Main app accesses Plugin1 or Plugin2 using predefined interface according to the scenario.
Plugin1 and Plugin2 performs entirely different functions depending on the case and displays corresponding strings from inside the plugin dll. (These strings has to be localized to current culture)
Note:
1. Once setup, main app should not have any changes for a plugin change (obviously)
2. Plugins should not have resources outside
Thanks
I may be missing something, so correct me.
In my shop we simply include resource files in the referenced DLLs. We take those resource files and send them to a translation service. I think as long as you're storing all of your localizable strings in resource files, as opposed to hard coding them, you should be ok in terms of localization.
Another thing to consider, however, is screen real estate. Some character sets take up more space than others. This is usually a problem for us when we make the translation from U.S. English to Chinese.

How to create a multi-lingual site

I am about to start on a project which must support a number of European languages. All static content on this site must be translatable between these languages. I have heard of satellite assemblies and have heard that they are used for multi-language sites in .NET but this was a long time ago. Is this still current practice in .NET? I'm using ASP.NET MVC.
If you're using ASP.NET MVC, one option would be to use a different resource for each view. I wrote an article about it, maybe it can be of help:
ASP.NET MVC Localization: Generate resource files and localized views using custom templates
Without the satellite part, you can add a App_GlobalResources folder to the project and add *.resx files for each language. You can have one resource file for the whole project, or one per ASP.NET MVC Area or however you see fit, but you don't need to have more then 1.
App_GlobalResources
MyResources.resx (Neutral / Default language translated texts)
MyResources.en-GB.resx
MyResources.de-DE.resx
In MyResources.resx
Name Value
TextID Some text which will be localized to the end user.
In Global.asax.cs (Application_PreRequestHandlerExecute)
// Set it according to cookies/Session etc.
System.Threading.Thread.CurrentThread.CurrentUICulture = "de-DE";
System.Threading.Thread.CurrentThread.CurrentCulture = "de-DE";
Then in the Views and PartialViews (e.g. MyView.cshtml).
<span>#Resources.MyResources.TextID</span>
Optional:
The Resources can be added as a link, and use custom namespaces.
BuildAction: Embedded Resource
CopyToOutputDirectory: Copy always
CustomTool: PublicResXFileCodeGenerator
CustomToolNamespace: MyNamespaceHere
mToolNamespace: MyNamespaceHere
Then they would be accessible via.
<span>#MyNamespaceHere.MyResources.TextID</span>
This is a general way to use (normal / linked) resources in ASP.NET MVC. If you use "Add as link" you can have one physical copy in a separate project.
Satellite:
Some info on satellite assemblies:
MSDN: Creating Satellite Assemblies
A MSDN Blog: Introduction to Satellite Assemblies

How to get installed image editors

Is there a code to get all the image editing software the user has installed?
I would like to know how to list all the applications by going through registry, is there any way to then filter out only the apps that can edit images, like Paint, Photoshop, etc...?
Thanks!
Here is an example for any generic file type:
How to get recommended programs associated with file extension in C#
If you look for jpg, png, etc. you'll get image editors.
No.
There is no expectation that every application developer somehow places metadata tags for their application inside of the registry (or wherever)... and, if for some reaosn a few handful of application developers did there is no way to guarantee the consistancy. Not to mention that application developers don't always use the common words you'd expect for their applications... Not every image editing application has the word "Photo" in it (for example, Picasa from Google).
The best you can hope for is to build some keywords to look for, add in a list of famous applications that don't conform to the keyword conventions your expecting ("Paint", "Photo", "Image", etc.), and work with that... either that or create a large database yourself to check against. Also, as other answers/comments have indicated, looking for applications that are used for specific extensions is helpful.
Nothing guaranteed though.

Different language resources

I need to create application with different language support. Language is setting up in login window (for example). I think I need to create a number of resx files and dynamically change em, depends on language I need.
Am I right? If so, how to make different resx files and change them in that way?
Thanks a lot!
Yes, you are right. You will need separate resx files for each language. Once you change the language, translations from respective language file will be picked and used
Take a look at this simple tutorial. It uses the Markup Extensions for changing the language at runtime. It is a simple and elegant solution

Categories