my "(" ")" get flipped when I try to write text with Hebrew (rtl).
I look up in the internet but its don't work for me like:
locale: const Locale('he', 'IL'),
localizationsDelegates: const [
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('he', 'IL'),
const Locale('en', '')
],
.
.
.
and:
return Directionality(textDirection: TextDirection.rtl, child: TabsScreen());
after a lot of test I find that the problem trigger when the phone settings is on English or another language but if the settings on Hebrew is work.
You can use the direction in text field to switch between rtl and ltr
Text(
direction : selectedLanguage == 'hebrew' ? TextDirection.rtl:TextDirection.ltr,
)
Related
I'm trying to translate an app in differents languages but facing a problem for languages inside fromSubtags (ukranian & russian)
I've looked in the doc internationalization so I can't declare them as const Locale("ru", "RU") & const Locale("ru", "UA")
I have to use Locale.fromSubtags()
It can exists only one app_ru.arb so how can I add ukranian in this json file an use it depending of the phone language?
L10n
class L10n {
static final all = [
const Locale("bg"),
const Locale("fi", "FI"),
const Locale("hu", "HU"),
const Locale("ja", "JP"),
const Locale("pl", "PL"),
const Locale.fromSubtags(languageCode: "ru"),
const Locale.fromSubtags(
languageCode: "ru",
countryCode: "RU"
),
const Locale.fromSubtags(
languageCode: "ru",
countryCode: "UA"
),
];
}
app_ru.arb
{
"language": "ru-RU",
"currentTrends": "Современные тенденции",
"currentlyAtTheCinema": "В настоящее время в кинотеатрах",
"availableSoon": "Скоро будет",
"animations": "Анимации",
"adventure": "Приключение",
"videoNotAvailable": "Видео недоступно",
"types": "Категории:",
"recommendedTo": "Рекомендовано",
"play": "Чтение",
"downloadVideo": "Скачать видео",
"synopsisNotAvailable": "Синопсис недоступен",
"casting": "Актеры",
"gallery": "Галерея"
}
Ukranian to add
"language": "ru-UA",
"currentTrends": "Поточні тенденції",
"currentlyAtTheCinema": "Наразі в прокаті",
"availableSoon": "Доступно найближчим часом",
"animations": "Анімації",
"adventure": "Пригодницька",
"videoNotAvailable": "Відео недоступне",
"types": "Категорії:",
"recommendedTo": "Рекомендовано на",
"play": "Читання",
"downloadVideo": "Завантажити відео",
"synopsisNotAvailable": "Синопсис недоступне",
"casting": "Актори",
"gallery": "Галерея"
Thanks in advance
Problem solved
Settings > Languages, there's is two "kinds" of ukrainian.
Russian (Ukrainian) Русский (Украина) & Ukrainian (Ukrainian) Українська (Україна) select the second one.
And it will works using app_uk.arb
I have integrated flutter localizations dependent of system language, works very well.
But I want to "force" language programmatically, without matters on system language.
My app root:
return GetMaterialApp(
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('sr', ''),
Locale('en', ''),
],
My lang config file:
arb-dir: lib/l10n
template-arb-file: app_sr.arb
output-localization-file: app_localizations.dart
Any every next new entering into the app will "keep" the user choose preferred language.
Thank you!
You can add the locale attribute to your MaterialApp, like that:
// Content from your MaterialApp
locale: const Locale('sr'),
// More content from your MaterialApp
If you need change in another part of your app, you can change de Locale in your AppLocalizations class.
rebuild the app after do something like change the theme or change the current language , iam using the ( easy_localization: ^3.0.0 ) package to change the lang
EasyLocalization(
child: MyApp(currentMode: currentMode),
supportedLocales: const [
Locale('ar'),
Locale('en'),
],
path: 'assets/translations',
startLocale: const Locale('ar'),
assetLoader: const CodegenLoader(),
),
If you're looking for the solution to this problem, this one works perfectly(tested) !
Add the package phoenix from here
Wrap your main widget with Phoenix
void main() {
runApp(
Phoenix(
child: App(),
),
);
}
Call rebirth method anywhere in your app like so Phoenix.rebirth(context);
Or make use of state management solutions like riverpod.
You place your settings in a provider and watch it on the pages that should change when the state updates.
When working with this package for localization, and base translation done in EN, I want my 2nd language to show keys if they are present in 2nd language json file, but if they are not, to consume en.json equivalent value. Issue is that by default this package shows key that doesn't exist in JSON file, instead of fallback translation file value. Is there a way to override this?
Usage of the plugin in main.dart file
runApp(
EasyLocalization(
child: MyApp(),
useOnlyLangCode: true,
fallbackLocale: Locale('en'),
supportedLocales: [
Locale('en'),
Locale('es'),
],
path: 'lang',
),
);
And when I want to translate a key that exists in en.json, but doesn't exist in es.json file it looks like this:
tr('appTitle');
Expected result would be "Hello world", but I get "appTitle" on the screen.
Old question, but since I just ran into the same problem:
There is now(?) a parameter "useFallbackTranslations" that you have to set to true. Indeed a bit counterintuitive, because one would assume that setting fallbackLocale should be enough.
EasyLocalization(
fallbackLocale: const Locale('en'),
supportedLocales: const [
Locale('en'),
Locale('es'),
Locale('de'),
],
useOnlyLangCode: true,
useFallbackTranslations: true, // <------
path: 'assets/i18n',
child: const MyApp(),
))
This is the EasyLocalization settings in runApp:
runApp(
EasyLocalization(
useOnlyLangCode: true,
useFallbackTranslations: true,
path: LanguageManager.langAssetPath,
supportedLocales: LanguageManager.instance.supportedLocales,
startLocale: LanguageManager.instance.dlLocale,
fallbackLocale: LanguageManager.instance.dlLocale,
child: const App(),
),
);
And the separated LanguageManager class
class LanguageManager {
LanguageManager._init();
static LanguageManager get instance => _instance ??= LanguageManager._init();
static LanguageManager? _instance;
static const langAssetPath = 'assets/translations';
final dlLocale = const Locale('en', 'US'); // necessary
final enLocale = const Locale('en');
final trLocale = const Locale('tr');
List<Locale> get supportedLocales => [dlLocale, enLocale, trLocale];
// constants
static const supportedLanguages = ['en', 'tr'];
Locale getCurrentLocale() {
return supportedLanguages.contains(getCurrentLang)
? Locale(getCurrentLang)
: const Locale('en');
}
String get getCurrentLang => Platform.localeName.substring(0, 2);
}
Finally assets/translations folder must en-US.json, en.json and tr.json
Don't forget generating
PS: This solution is from Veli Bacik in Turkey
I want to create an application that the intro app of my app to be LTR and other parts to be RTL. I found some code for RTL:
localizationsDelegates: [
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
Locale("fa", "IR"), // OR Locale('ar', 'AE') OR Other RTL locales
],
locale: Locale("fa", "IR")
But it is used for all parts, not some parts, please help me.
I used this package for my app intro