WaveVR_Resource¶
Contents |
Introduction¶
WaveVR_Resource.cs provides an alternative way to access string/locale resources from native Android. Developer appends application’s resource using AAR file into Android resource system, and then use it via WaveVR_Resource to archive changing language based on device’s locale or preferred locale. Android system will feedback string value by different locale.
- string getString(string stringName)
returns Android resource string by name in the string.xml, the return value will be default to system configuration.
- bool setPreferredLanguage(string lang, string country)
set prefer language to WaveVR, all string values will be returned by selected language and country after this API returns true. If there is no corresponding resource in Android, language will be default to system configuration.
lang : 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()
restore WaveVR resource setting to default.
- string getStringByLanguage(string stringName, string lang, string country)
returns Android resource string by name in assigned language and country.
- string getSystemCountry()
returns string of current system country code, ex. us.
- string getSystemLanguage()
returns string of current system language code, ex. en.
Resources¶
Sample scene Resource_Test is located under Assets/Samples/Resource_Test/Scenes
Sample script ResourceDemo.cs is located under Assets/Samples/Resource_Test/Scripts
Sample AAR wavevr_resdemo.aar is located under Assets/Plugins/Android
How to add resource into Android¶
- Developer is suggested to reference Android document to aware how to add resource into Android with application 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>
See into 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);
}