WaveVR_Resource¶
Contents |
Introduction¶
WaveVR_Resource.cs provides an alternative way to access string/locale resources from native Android. You will use an AAR to integrate the application’s resource into the Android resource system. Then use it via WaveVR_Resource to archive the changing language based on a device’s locale or preferred locale. The Android system will feedback the string value by a different locale.
- string getString(string stringName)
This returns an Android resource string by the name in the string.xml. The return value is the system configuration in default.
- bool setPreferredLanguage(string lang, string country)
This sets the preferred language to WaveVR and all string values will be returned by the selected language and country after this API returns true. If there is no corresponding resource in Android, the language is the system configuration in default.
Language : ISO 639 alpha-2 or alpha-3 language code, please refer to ISO 639
Country : ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code, please refer to ISO 3166
- void useSystemLanguage()
This restores the WaveVR resource setting to default.
- string getStringByLanguage(string stringName, string lang, string country)
This returns the Android resource string by name in the assigned language and country.
- string getSystemCountry()
This returns the string of the current system country code, ex. US.
- string getSystemLanguage()
This returns the string of the current system language code, ex. EN.
Resources¶
The sample scene Resource_Test is located in Assets/Samples/Resource_Test/Scenes
The sample script ResourceDemo.cs is located in Assets/Samples/Resource_Test/Scripts
The sample AAR wavevr_resdemo.aar is located in Assets/Plugins/Android
How to add resources into Android¶
- It is suggested you refer to Android documents to be aware of how to add resources into Android with an application’s APK.
Sample code¶
string.xml (default) in wavevr_resdemo.aar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="demo">demo</string>
<string name="test">test</string>
<string name="allow">allow</string>
<string name="reject">reject</string>
<string name="mytest">test1</string>
</resources>
string.xml (ja) in wavevr_resdemo.aar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="demo">ショー</string>
<string name="test">テスト</string>
<string name="allow">許します</string>
<string name="reject">断ります</string>
<string name="mytest">テスト1</string>
</resources>
Refer to the ResourceDemo.cs
private WaveVR_Resource rw = null;
// Use this for initialization
void Start () {
rw = WaveVR_Resource.instance;
Log.d(LOG_TAG, "system default language is " + rw.getSystemLanguage());
Log.d(LOG_TAG, "system default country is " + rw.getSystemCountry());
Log.d(LOG_TAG, "get string by system default language");
string tmp = rw.getString("allow");
Log.d(LOG_TAG, "get allow by system default language : " + tmp);
tmp = rw.getString("demo");
Log.d(LOG_TAG, "get demo by system default language : " + tmp);
tmp = rw.getString("reject");
Log.d(LOG_TAG, "get reject by system default language : " + tmp);
tmp = rw.getString("test");
Log.d(LOG_TAG, "get test by system default language : " + tmp);
bool ret = rw.setPreferredLanguage("zh", "CN");
Log.d(LOG_TAG, "set preferred language to simplified Chinese and get string = " + ret);
tmp = rw.getString("allow");
Log.d(LOG_TAG, "get allow by preferred language(zhCN) : " + tmp);
tmp = rw.getString("demo");
Log.d(LOG_TAG, "get demo by preferred language(zhCN) : " + tmp);
tmp = rw.getString("reject");
Log.d(LOG_TAG, "get reject by preferred language(zhCN) : " + tmp);
tmp = rw.getString("test");
Log.d(LOG_TAG, "get test by preferred language(zhCN) : " + tmp);
Log.d(LOG_TAG, "get string in dedicated language");
tmp = rw.getStringByLanguage("demo", "zh", "TW");
Log.d(LOG_TAG, "get demo by zhTW : " + tmp);
tmp = rw.getStringByLanguage("demo", "en", "US");
Log.d(LOG_TAG, "get demo by enUS : " + tmp);
tmp = rw.getStringByLanguage("demo", "ja", "JP");
Log.d(LOG_TAG, "get demo by jaJP : " + tmp);
rw.getStringByLanguage("demo", "xx", "xx");
Log.d(LOG_TAG, "get demo by xxxx: " + tmp);
Log.d(LOG_TAG, "set back to default language ");
rw.useSystemLanguage();
tmp = rw.getString("allow");
Log.d(LOG_TAG, "get allow from native : " + tmp);
tmp = rw.getString("demo");
Log.d(LOG_TAG, "get demo from native : " + tmp);
tmp = rw.getString("reject");
Log.d(LOG_TAG, "get reject from native : " + tmp);
tmp = rw.getString("test");
Log.d(LOG_TAG, "get test from native : " + tmp);
}