nativescript-rtl / ui

Add right-to-left support to the NativeScript framework
MIT License
24 stars 3 forks source link

Provide demo #6

Closed Izrab closed 5 years ago

Izrab commented 5 years ago

Unlike many other plugins, this plugin does not have any demos

xlmnxp commented 5 years ago

is it important?

Izrab commented 5 years ago

Yes, it is. Imagine nativescript-plugin-firebase did not demos.

xlmnxp commented 5 years ago

@Izrab I will add it soon

Izrab commented 5 years ago

Add a real world example, like an app which supports English and Arabic, user changes language in settings and app instantly becomes RTL. Use this localization style for the demo إن شاء الله

export const localisedStrings = {
  test: {
    "en": "test",
    "ar": "اختبار",
    "ku": "تاقیکردنەوە",
  },
  cancel: {
    "en": "Cancel",
    "ar": "إلغاء",
    "ku": "داخە",
  }
}

export function getLocalisedString(
  name,
  locale,
) {
  const baseStrs = localisedStrings[name];
  const baseStr = baseStrs[locale];
  return baseStr;
}

// Example usage: getLocalisedString("test", appSettings.getString("language"))
xlmnxp commented 5 years ago

@Izrab you can use https://github.com/EddyVerbruggen/nativescript-i18n for multi-languages support

I used it (Angular):

<RtlGridLayout [isRtl]="'rtl' | L" columns="auto *"></RtlGridLayout>

i18n/ar/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">يهمني</string>
    <string name="title_activity_kimera">يهمني</string>
    <string name="lang">ar</string>
    <string name="rtl">true</string>
</resources>

i18n/en/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">yahmini</string>
    <string name="title_activity_kimera">yahmini</string>
    <string name="lang">en</string>
    <string name="rtl">false</string>
</resources>