2

I am using Assets files as help files in my app and have well over a dozen. I am porting the app to multiple languages. Where do the alternative language asset files go?

I am already using the "res/values" directories for language files (values, values-es, etc) for use within the app. I thought the "Assets" directory was for help files and items like that.

I am trying to NOT muddy my values folders with the many help files that I am including and was using "activity.getAssets().open( file )" to read the files.

Also, some of these "Asset" files are different language pictures.

Veve
  • 6,643
  • 5
  • 39
  • 58
miannelle2
  • 281
  • 2
  • 5
  • 14
  • Possible duplicate of [Change language dynamically using androids multilanguage support?](http://stackoverflow.com/questions/4639078/change-language-dynamically-using-androids-multilanguage-support) – Chisko Sep 22 '16 at 21:00

3 Answers3

2

For the voice recognition in my app (using Vosk) I have defined the specific asset folder as resource string. I.e. values\strings.xml contains:

<resources>
    <string name="language_directory">vosk-model-small-en-us-0.15</string>
    ...

and values-de-rDE\strings.xml contains:

<resources>
    <string name="language_directory">vosk-model-small-de-0.15</string>
    ...

So I can access the asset directory via

val assets = Assets(activity)
val assetDir = assets.syncAssets()
val modelDir = activity.getString(R.string.language_directory)

recognitionListener.model = Model("$assetDir/$modelDir")

This way the correct directory is always chosen based in the active locale.

In my case, those are located at models\src\main\assets\sync\<language_directory>

Corbie
  • 819
  • 9
  • 31
1

Can you put the files in /res instead of /assets? This has built in support for multiple languages, there is an easy to follow guide here.

Basically, if your original text is in /res/values/strings.xml, for example, you would put your translations in /res/values-{ISO LANGUAGE CODE}/strings.xml

For example, your French translation would be in /res/values-fr/strings.xml.

Android will pick the appropriate translation file according to the locale of the user's phone.

There are some good explanations of the other differences between /res and /assets here.

Community
  • 1
  • 1
vek
  • 15
  • 2
  • 5
  • While I could do this, it would muddy the values folders with these raw files. And some of the files are pictures. – miannelle2 Sep 23 '16 at 11:29
  • For the pictures, you can do the same with res/drawable, eg res/drawable-fr. But the assets folder doesn't support this, so if you want to put the help files in there, you will have to select the correct files manually. – vek Sep 23 '16 at 19:53
0

Make folder in assets: 1. htmlpagesNL 2. htmlpagesUS

Copy file from htmlpagesNL and paste to htmlpagesUS and Translate

Use url inside Nl string file: file:///android_asset/htmlpagesNL for NL translation Use url inside Us string file: file:///android_asset/htmlpagesUS for US translation

Support different languages Support different languages and cultures

Danny Eersel
  • 3
  • 1
  • 4