C# Creating a setup for multi-language - c#

I have added multi-language using the short article below.
When you add for example German language you will have these files:
formMain.resx
formMain.de-DE.resx
formMain.Designer.cs
formMain.cs
In first file you will have resources for neutral language, like strings, images, ..
So now you need to add also resources for strings used in code. Add a new resource file and name it formMain.Strings.resx
Then i will enter name, value pair for every string that should be translated. When you add resource file then it is automatically typed because another file with name formMain.Strings.Designer.cs is automatically regenerated on every close of resx designer.
Add another resource with name formMain.Strings.de-DE.resx. Add the same Name key's from previous resource, and just change the Value with coresponding german words. Now to access created resource from the source it will be like this.
MessageBox.Show(formMain_Strings.SameStringName);
However, I have changed my to Thai language. Everything works fine when I run my app in VS.
However, as soon as I add a setup project and install on the clients machine it won't change the language to Thai and just keeps to the default language.
So I have added the resource files and the th-TH dll to the project setup. And I still get the same problem.
Packaging file 'Lang.Strings.resx'...
Packaging file 'MultiLanguage.resources.dll'...
Packaging file 'MultiLanguage.exe'...
Packaging file 'Lang.Strings.th-TH.resx'...
As everything works fine when running in visual studio. Is there something I need to do to get it to run once its been installed. All the properties for each of the file I have keep the default.
Many thanks,
=========
static void Main()
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("th-TH");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

I found the answer
Click the Setup Project in Solution Explorer and then click Add\Project Output\ . From dialog select the project for which you want to include localization (satelite) assemblies and then select Localized resources.
After the installation in the folder that I install to, I have the th-TH folder which includes the satellite assembly.
Thanks,

Try adding in this at the app's startup (if it's not there):
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;
Here is a short article discussing some of the options of how to make this work, and options for selecting the locale at runtime.
Edit after comments:
Make sure your satellite assembly is in the appropriate place, and built correctly. From that article I referenced:
"When .NET runtime starts an application it looks for a possible satellite assembly file. A satellite assembly file is a resource only assembly file that has .resources.dll extension instead of .exe ir .dll (if the main assembly is a library). Satellite assembly files always locate on a language specific sub directory of the applciation's main directory. If application file is Converter.exe then the Japanese satellite assembly file is ja\Converter.resources.dll."
There are a few things that you should check here. Check the name of the assembly. Also, make sure it's in the proper location. In your case, it should be in a th-TH subdirectory with the appropriate name under your executable. If it's there, it should be found and used properly.
Here is another good source of information about this topic.

Related

Globalization unable to find appropriate resources

I'm trying to globalize an mvc application (french and english), here's what I did:
1) Created an App_LocalResources folder and added 2 files:
Resources.resx (will contain french) and
Resources.en.resx (will contain english).
Then I added one resource in each file with the same name (just to test) and modified the access modifier to Public (for each file)
2) Specified the french culture in global.asax
protected void Session_Start()
{
string userLanguage = Request.UserLanguages[0];
string cultureName = CultureHelper.GetImplementedCulture(userLanguage);
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
HRP.App_LocalResources.Resources.Culture = Thread.CurrentThread.CurrentCulture;
}
CultureHelper is a helper I found online, it determines the correct name of the culture (credits to the author): http://pastebin.com/JkhjJg4N
3) Added a test string to display in my view:
<p><span class="Title">#HRP.App_LocalResources.Resources.EmployeesTitle</span></p>
And the exception is:
[MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "HRP.App_LocalResources.Resources.resources" was correctly embedded or linked into assembly "HRP" at compile time, or that all the satellite assemblies required are loadable and fully signed.]
Please help.
I solved it thanks to a friend's tip:
the problem was that the .resx files were builded as Content so all I needed to do was:
Right click on your ResourceFile -> Properties -> Change the "Build Action" property from "Content" to "Embedded Resource"
I have done a small example showing how your code should work out.
Set the build action of the resources to embedded resource
Enter custom tool PublicResXFileCodeGenerator
Afterwards your resources will be available within your code
razor file
<p>#NAMESPACE.App_LocalResources.YOUR_RESOURCE_FILE.RESOURCE_NAME</p>
I have used another custom tool as K. Scott Allen stated
Resx Files Outside Of Special Resource Directories resx properties in MVC
If you add a resx file to any other folder in an MVC project or
class library, the resx is automatically set to be embedded into the
project’s output assembly - this is good. The IDE also assigns the
resx a custom tool of ResxCodeFileGenerator to generate a strongly
typed wrapper - this is good. The generated class is internal by
default – this is bad. The assembly created for a view (by ASP.NET)
won’t be able to use the internal class because it is in a different
assembly – the project assembly compiled in Visual Studio.
So if you add your resource files to the special folders - anything goes right. If you choose to place it on another path it would fail (unless you use the custom tool).

Proper procedure to import existing RESX files into a C#/WPF project

I have my auto generated Resource.resx file set up with keys and strings. I also have three other resx files for German, French and Spanish given to me from translators. I'm not able to get the localization functioning and I suspect that the resx files aren't being called correctly. I added them to the project by dragging them into the solution explorer under "Properties". I have a nagging suspicion that just dragging them in isn't creating the proper connections behind the scene.
Now It's totally possible my issue lies somewhere else. If anyone can tell me whether it's ok to add resource files this way or if not, what the correct way is, it would save me tons of time spent chasing my tail. Thanks!
Resx files in Visual Studio include a special tool which is run at build time and translates them into embedded resources. Right-click your original VS-created resx file and click Properties. You should see Build Tool or something similar. Also note the resource type (Embedded, etc.). Make sure that you match these settings for your manually added files.
Once this is set up, you will need to use the CurrentUICulture property to tell .NET to pick up the appropriate resources. You can choose to change the culture/language at install-time or run-time. Here is a comprehensive tutorial which describes the various options available to you:
WPF Localization Using RESX Files
That said, as a best practice, translated Resx files are generally deployed as satellite assemblies. The main application DLL/EXE contains only the language neutral resources file. Other resource files are compiled into separate assemblies and deployed side-by-side with specific naming conventions. This allows you to dynamically add translations, localizations, etc. even after the application is deployed. Here's an introduction: Packaging and Deploying Resources in Desktop Apps

Cannot assign image in button in windows application

I am getting this error in my windows application. I have made build action " embedded resource and also make access modifier of image public. But still I am getting bellow error.
Please help me out with this error.
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure OPDManagmentSystem.Properties.Resources.resources was correctly embedded or linked into assembly OPDManagmentSystem at compile time, or that all the satellite assemblies required are loadable and fully signed.
When I copied over files, and rebuilt a new VS2008 project, there was no hierarchical relationship in Visual Studio Solution Explorer for the resource file. For example, ExceptionMessage.resx and ExceptionMessage.Designer.cs were at the same level; whereas normally the Designer.cs file is indented under the .resx file.
So what I did was create a new .resx file, and carefully copy over using NotePad and filemerge programs, pieces of the .resx file and .cs file. Then it worked fine...

VS 2008 does not understand .resource files

I'm trying to add globalization support to my C# application.
According to MSDN, there should be one embedded resource file for neutral culture and satellite DLLs with resource files for other cultures.
I've created 2 satellite DLLs without any problems and got my app to automatically load right one using ResourceManager. But I can't embed default neutral culture resource file into my executable. When I remove all satellite DLLs or set culture to some culture I don't have satellite DLL for, I get exception "Could not find any resources appropriate for the specified culture or the neutral culture." when application attempts to create ResourceManager.
It looks like VS 2008 does not include my .resource file into main assembly. I've tried different ways to get resource file embedded: compiling it by resgen.exe from text file and adding it to the project; changing its name to add second .resources extension; creating .resx file with same name; etc. And I still don't see the way to get resource file embedded and used by ResourceManager - I'm having same exception.
What is the right way to add default neutral culture resource file to application in VS 2008 ?
Ok, I've solved this problem by little 'hack'.
I've compiled resource file using resgen.exe, as described in MSDN, then added it to the project, renamed it to "resources" and changed build action from "None" to "Embedded resource".
Looks like VS 2008 adds "." as prefix to resource file name. So if u will name your resource file ".resources" it won't work cuz actually VS will name it "..resources".
in .Net the resource files are using the .resx extension. To have it 'embedded' in your project, make sure the "Custom Tool" in the properties page of the .resx file is using the "ResXCodeGenerator"
Hope this helps,

Resource files and satellite assemblies

I am, for lack of a better word, a newbie to Localization and resource files. I am trying to localize an application I am working on and I want to do it using resource files and satellite assemblies, but I can't figure out how to do it correctly. Here is what I have so far:
In my project directory: I created the files LanguageText.resx and LanguageText.nl.resx
In my project/bin directory: I created the folder "nl"
In my project/bin/nl directory: I used ResGen.exe to create LanguageText.nl.resources file from LanguageText.nl.resx file, then I used AL.exe to create the project.resources.dll file. That .dll file is in the bin/nl folder. It assembled ok and now I have nl/project.resources.dll in my project/bin/debug folder as well.
My problem is that I apparently do not have a neutral language file or resource embedded in my program, but I can't find any info on how to do that. The only info I can find about embedding resources in this manner is related to satellite assemblies. How do I embed the neutral language resource?
Any help or direction is appreciated.
Thanks,
Mike
You can do it with the help of AssemblyInfo. Go to AssemblyInfo.cs and add the attribute
[assembly: NeutralResourcesLanguageAttribute("en-US",UltimateResourceFallbackLocation.Satellite)]
Make sure to add using statement using System.Resources; at the top. The above line indicates that the neutral resource language of your assembly is 'en-US' and this is a Satellite assembly.
The fallback resources should be placed in LanguageText.dll in the bin folder.
Alternatively, you may add an System.Resources.NeutralResourcesLanguageAttribute attribute to the LanguageText.dll assembly,
and specify a default culture used if the culture is invariant, or there is no match for a given culture.
Generate the nl assembly, call it LanguageText.resources.dll, place in bin/nl folder.
Verify that this works, by setting the culture on your thread and use a ResourceManager to retrieve resources.

Categories

Resources