Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localization of assets files

I have several html files in assets folder. How can I localize them? Is my only option to put some hardcode to pick the right file based on locale?

like image 779
mishkin Avatar asked Mar 25 '11 02:03

mishkin


People also ask

What is asset localization?

What is Asset Localization? Easy-to-use and generic asset localization system for Unity. With Asset Localization, you can easily localize your built-in Unity game assets. Also you can create custom localizable asset functionality for your custom assets. Available on Asset Store and Unity Package Manager.

What is file localization?

In software localization projects, translatable strings are first collected in so-called “localization files” or “resource files.” These files are then handed off to translators who translate strings and thereby create copies of the original files now containing equivalent strings in a different language.

What is the process of localization?

Localization is the process of adapting a piece of content's full meaning for a new region, including translation, associated imagery, and cultural elements that influence how your content will be perceived. Localization is all about making your website feel like it was written with that audience in mind.


2 Answers

This isn't supported directly but here is what I have done...

Separate your files into groups by country code (like what you would do for normal resource files) and then create a localized string in each of your localized string.xml files called something like "prefix" (where prefix would be "en" for English for example).

Then when you build your asset filenames simple use something like getString("prefix") + "-" + "<name-of-asset->.

At least some variation of the above should work for you.

like image 162
Andrew White Avatar answered Oct 05 '22 00:10

Andrew White


Put your files into the assets folder with local suffix. Define a String resource 'myLocalizedFileName' for every file and get the filename via R.string.myLocalizedFileName.

Example:

Folder structure:

assets/ assets/help.html assets/help_de.htlm 

String resources for every language in res/values/strings.xml:

<resource>   <string name=helpFile>help.html</string> </resource> 

WebView calling:

public class HelpActivity extends AppCompatActivity {   protected void onCreate(Bundle savedInstanceState) {     ...     findViewById(R.id.helpWebView)       .loadUrl("file:///android_asset/"           + getString(R.string.helpFile));   } } 
like image 21
Christian Schulzendorff Avatar answered Oct 05 '22 00:10

Christian Schulzendorff