2017-08-17 71 views
0

我對nativescript很新穎。我想弄清楚如何使用strings.xml中的字符串值,所以我可以本地化我的應用程序。在Nativescript中使用i18n字符串資源Android

我的佈局看起來像這樣。

<StackLayout class="page"> 
    <label [text]="@string/a_value"></label> 
    <Label text="Hello world with tap!" class="yellow"></Label> 
    <button text="Tap me my friend" (tap)="tapTheButton()" class="red"></button> 
    <label [text]="text" class="blue"></label> 
</StackLayout> 

@ string/a_value應該從res/values/strings.xml文件中獲取字符串。

歡迎任何幫助!

回答

0

@string/string_name在描述NativeScript佈局時不是有效的表示法,因爲它是嚴格的Android插入字符串的方式。

您可能可以訪問資源管理器(https://developer.android.com/reference/android/content/Context.html#getResources())並獲取名稱爲a_value的字符串的字符串值,然後將數據綁定到您的標籤。這隻適用於Android。

有一個由社區完成的NativeScript插件,旨在使國際化變得抽象,以便Android和iOS均可使用 - nativescript-i18n。

+1

謝謝,我看了一下插件,它爲我工作。乾杯! – Wouter

相關問題