How do I create localized resources in Visual Studio? - visual-studio

I'm trying to add culture specific translations for the strings in my Resources.resx file and can't find anywhere to do this in visual studios.

Create a new resource file with an additional suffix that matches the culture string you're looking for.
For example, if you'd like to have translations associated with the neutral French culture ("fr") then create a resource file named Resources.fr.resx with your translations in it.

Related

Intellisense/Autocomplete for a string representing a file path in Visual Studio

I work on an ASP.NET MVC 5 website. A while ago, I created a helper method to include specific CSS files with our Views - it accepts a string as input representing the file path to that CSS file, relative to the root of the project.
E.g:
AddStyleSheet("/path/to/the/file.css")
What I would absolutely love is a way to provide Intellisense in Visual Studio (ideally 2019, but 2022 could also work if necessary) to help create that string by showing relevant files, similar to what we get for #import statements in SCSS files (pictured), where a nice prompt pops up showing files at the current location represented by the file string.
Happy to change the helper method however necessary to accomplish this - is something like this possible? Maybe via an extension or some decorator on the string in the function?

Alter Multilingual App Toolkit source language

So I understand how Multilingual App Toolkit 4.0 works and it works great for my Xamarin.Android project. The default language is English, and with MAT we've translated it to Dutch and German.
Then comes the translator along and asks about how to make changes to the English texts, which is my source texts and the basis of all translations. The source texts (English) are in a file Resources\values\Strings.xml. Alter a string there, would invalidate all translations (Dutch and German).
Besides invalidation, I can't send my translator the normal .xlf file, because all source texts are in the Strings.xml file.
So my question is, how can my translator alter the source language texts in the most easy way (preferably with an .xlf file)?
The short answer is that you can't. The design of the Multilingual App Toolkit focused on providing easy support for translation into other languages. The concept of providing source content editing was not considered.
That said, as a workaround you could add another variant of English. For Android apps, the default is English Neutral (en), so adding en-US or en-UK would create the XLIFF file that your translator / proofer could edit using the same tooling (e.g.: Multilingual Editor) to provide source content proofing. If using the same translator for proofing and translating, they could apply the translation based on the update English string to the Dutch and German files.
When you receive the XLF files back ensure all the resource in the proofing English XLF (e.g.: en-US) are marked as need review, translated or final (basically anything except 'New'). The reason is that the Multilingual App Toolkit does not include untranslated resource in the generated target resource file. (The reason is for language fallback purposes in Windows apps).
Now you can import the proofed English file with the other XLF file and build. Copy the entire contents from the proofed English resource file(s) overtop the original source files (recommend Comparing first). When you next build, you will receive warnings that the source resources have changed after the translation, but you can just review and clear those warning in the editor, or clear them globally within the Visual Studio IDE.

Prevent language translation of resource file in Visual Studio 2015

When using the Multilingual App Toolkit extension (version 4) in Visual Studio (2015) is there any way to prevent one of the resource files in the project from being translated?
In the Multilingual App Toolkit I have two languages added using Add translation languages...
I've now added a new resource file resourceImages.resx to my WinForms project to contain images that should not be localized.
The toolkit has automatically created resourceImages.fr.resx and resourceImages.de.resx. Is there any way I can prevent this - I do not want the images to have translated versions and I don't want them to appear in the xlf translation files that our translators will receive.
The author of the Multilingual App Toolkit has now answered this question in the Q&A tab here
There is no option to ignore resource files with MAT. However, by default the entry in the XLF file is a reference to a image location and not the image itself. Marking the image resource(s) as Translate = 'No' in the XLF file will prevent the images references from being added to the target language image resource files. This is because resources with a Translate = 'No' are not added to the target resource file. This should allow you to use a single image for all languages without any project bloat.

Localizing for sub-cultures on WP7 not getting picked up

I am trying to localize my wp7 application and I need to have different strings for de-DE and de-AT because there are some language differences between those two cultures even though the basic settings are the same.
I did the following to achieve this:
Created an AppResources.resx file for the default English text
Created an AppResources.de-DE.resx file for the German text
Created an AppResources.de-AT.resx file for the German text for Austrian sub culture
in the Assembly Information... in the project properties I set English as my Neutral Language
I closed the solution, opened up my project.csproj file and changed the <SupportedCultures/> to the following: <SupportedCultures>de-AT;de-DE</SupportedCultures>
I added a new Class LocalizedStrings, registered it in Application.Resources in App.xaml and changed the output string accordingly.
Both the Emulator as the handset are set to Austrian Locale, System.Globalization.CultureInfo.CurrentCulture.ToString(); returns de-AT, but regardless of that the texts defined in AppResources.de-DE.resx are used and not the ones defined in the file for the Austrian culture.
Any idea how I might solve this issue?
You should check the CultureInfo.CurrentUICulture, not the CurrentCulture!
That is the property that controls what resources get loaded for interface!
The value of CurrentUICulture should match the one selected in the phone/emulator Settings -> Region+Language -> Display Language.
Ideally, you can always override the system imposed CurrentUICulture by setting a different CultureInfo on Thread.CurrentUICulture.

Best way to deploy and reference an XSLT file

In a visual studio project I have three layers, Data Layer, Business Layer and Presentation Layer.
In the Data Layer I have a few XSLT's that transform some objects into an email, all works fine but I have discovered that the XSLTs do not get built/copied when building.
I have currently, created a folder in the deploy location and placed the XSLT's there but I am concerned about relying on a manual process to update these.
Has anyone encountered a similar issue and if so how did they get around it.
It smacks of changing the MSBuild script to copy the build artifacts to the required location, does anyone have examples of this?
Thaks
If you are using Visual Studio 2005/2008, the easiest way to do this is by including your XSLT files as project resources.
Open the Properties for your project.
Select the Resources tab. You will probably see a link that says "This project does not contain a default resources file. Click here to create one." Go ahead and click on that.
Click the Add Resource drop-down near the top and select Add Existing File.
Browse to your XSLT files and select them.
After you have done this, you can easily access the resources in the following manner:
// To get the contents of the resource as a string:
string xslt = global::MyNamespace.Properties.Resources.MyXsltFile;
// To get a Stream containing the resource:
Stream xsltStream = global::MyNamespace.Properties.Resources.ResourceManager.GetStream("MyXsltFile");
If you are using Visual Studio 2003, your best bet is to include those XSLT files as embedded resources for the DLL. In Visual Studio, select the file(s) in Solution Explorer, open the Properties pane, and change the Build Type to "Embedded Resource". You can then use the GetManifestResourceStream method to get a Stream containing the XSLT(s). The name to pass will be based on the default namespace of your assembly, the folder containing the file, and the name of the file.
For example, say your data layer assembly has a default namespace of My.DataLayer. Within your data layer project you have a folder named Templates which contains a file called Transform.xslt. The code to get your XSLT would look like this:
// There are numerous ways to get a reference to the Assembly ... this way works
// when called from a class that is in your data layer. Have a look also at the
// static methods available on the Assembly class.
System.Reflection.Assembly assembly = (GetType()).Assembly;
System.IO.Stream xsltStream = assembly.GetManifestResourceStream("My.DataLayer.Templates.Transform.xslt");
For more information check out this article on CodeProject.
Obvious question maybe, but still has to be asked, did you include the folder containing the XSLT's in the project itself? Is this a web or forms app?
In VS, it is easy to set the properties of the XSLT files in the project to copy on build, by default they do not.
I may have explained myself poorly.
THe Data layer is a class library that a the presentation layer references.
On building the DataLayer I can get the XSLTs to output to the Bin directory of the DataLayer. However when I build and publish the presentation layer, it correctly grabs the DLL but not the XSLTs

Resources