Flutter Tutorial - Localization & Internationalization with INTL & ARB Files

Flutter Tutorial - Localization & Internationalization with INTL & ARB Files

HeyFlutter․com

3 года назад

68,350 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Mateus Félix
Mateus Félix - 02.09.2023 22:29

Good practice tip for everyone:

Create an extension like so you can access the translation values like Text(context.locale.yourTranslation)

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

extension LocalizationsExtensions on BuildContext {
AppLocalizations get locale => AppLocalizations.of(this)!;
}

You can set also for other situations like access the Theme.of(context) colors properties:

import 'package:flutter/material.dart';

extension BuildContextExtensions on BuildContext {
ThemeData get theme => Theme.of(this);
TextTheme get textTheme => theme.textTheme;
ColorScheme get colorScheme => theme.colorScheme;

Color get backgroundColor => colorScheme.background;
Color get cardColor => theme.cardColor;
}

from Theme.of(context).colorScheme.background
to context.backgroundColor


:))))))

Ответить
Fraturkish
Fraturkish - 31.07.2023 11:37

is the description mandatory? @HeyFlutter

Ответить
Đức Nam Nguyễn
Đức Nam Nguyễn - 29.05.2023 18:07

Very helpful and informative. Thanks

Ответить
Joël Fah
Joël Fah - 14.05.2023 18:22

A very nice tutorial there. Always strainght forward. I like it. Keep up.
But pease, I tested your approach on Flutter web and it works like charm but I noticed that when ever I purposely reload the tab the locale is reseted to the system's locale. It doesn't take into consideration if it there were any changes before. Is there any way to persist the locale value after calling setLocale ?
Thanks

Ответить
sporttirol
sporttirol - 25.04.2023 16:46

Ich darf Dir mitteilen, dass ich aufgrund deiner Kurse programmieren gelernt habe. Dafür darf ich mich bedanken.

Ответить
عبد الحكيم عجاج
عبد الحكيم عجاج - 10.04.2023 13:17

very clear and tuff understanding with easy explaining thank you HeyFlutter

Ответить
Wishkova baksuzna statistika
Wishkova baksuzna statistika - 30.01.2023 18:24

How to modify the code to add supportedScript? I tried to add translations, add supportedScript in the list of languages, but it is not working.
Also returned Locale.subfromSubtags(), but seems it is not working.

Ответить
mohammed gamal
mohammed gamal - 29.01.2023 08:05

no Israel it is Palestine

Ответить
Mohammed Aymen
Mohammed Aymen - 18.11.2022 12:09

you are THE BEST 👌

Ответить
Stalk in stalk
Stalk in stalk - 11.11.2022 17:01

Schönes und hilfreiches Video.

Ответить
faizy 313
faizy 313 - 31.10.2022 11:40

how to translate data inside listView builder can someone help..?

Ответить
dhruvin prajapati
dhruvin prajapati - 27.10.2022 09:34

any short way to use AppLocalizations.of(context)!.languagein every page?

Ответить
Monika Sharma
Monika Sharma - 07.10.2022 12:12

Its showing me error when i add import statement @Johannes Milke Can you help what i did wrong

Ответить
Yamuna G
Yamuna G - 26.08.2022 09:41

plz help ..........AppLocalizations.of(context) getting null why?

Ответить
Amjad zayed
Amjad zayed - 30.07.2022 14:16

worked! many thanks

Ответить
FlutterShipp
FlutterShipp - 25.06.2022 16:47

Excellent explaination

Ответить
okokokokok ok
okokokokok ok - 07.06.2022 18:22

i can't use fr_FR code even when change my file name to app_fr_FR it cause an error arb not found, I tried this because when I set locale to null the app not used the system language so I tries to get it with Platform.localeName

Ответить
Ahsan Raza
Ahsan Raza - 04.06.2022 11:12

in-app-purchase video plz

Ответить
Ayako Haruto
Ayako Haruto - 30.05.2022 16:27

In my case my flutter gen folder is changed to generated and AppLocalization.delegate is changed to S.delegate, and lastly app_en.arb is changed to intl_en.arb, apart from these changes, it works superb, thank you :)

Ответить
Margareti Solan
Margareti Solan - 01.05.2022 18:55

Fantastic explanation!

Ответить
prem chandraseakaran
prem chandraseakaran - 28.04.2022 15:04

If I want to make German as my default app language, How can I achieve this case ?

Ответить
Bhumi Chaplot
Bhumi Chaplot - 31.03.2022 16:03

It's not showing any .dart_tool file

Ответить
Dong Nguyen
Dong Nguyen - 31.03.2022 14:00

hi Milke, such a great tutorial. But i have a question. How can we combine this with remote languages and words ? Thanks you

Ответить
utan
utan - 31.03.2022 06:20

Hum, long step and lots of files to do this, useful if your app doesn't need internet but will give increase App size, what I do if internet connection is necessary is send I payload with language code and reseive the translation from server, async is your friend and small footprint size for ur app.

Ответить
D TecHub
D TecHub - 28.02.2022 12:49

How can I fix the Flutter_localizations error on the Android Studio? - Target of URI doesn't exist
Error setting-up flutter_localizations package "Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'."
Please give a solution as soon as possible
Thank You!

Ответить
Remojo King
Remojo King - 24.02.2022 08:43

Thank you so much for this .Really love you bruh🥰😘😘😘😍💖💖

Ответить
Kwaku Kusi
Kwaku Kusi - 16.02.2022 23:40

dude you're so amazing, thank you very much

Ответить
palak pandey
palak pandey - 10.02.2022 13:35

by this i am able to change language in one page what if i want that language to reflect in all the app?

Ответить
Kardo Aziz
Kardo Aziz - 07.02.2022 11:09

thank you for the great tutorial, But I have a question, do you have any video that shows how to remember selected language after closing the application and reopening it ? your tutorial works fine but every time i close the application and open it it will go back to default language

Ответить
Álvaro Fernández
Álvaro Fernández - 11.01.2022 21:25

Thank you!! This helped me a lot. Nice tutorial!

Ответить
Kartik Patel
Kartik Patel - 22.12.2021 12:36

need help ..getting error

String getTranslate(BuildContext context, String key) {
return AppLocalizations.of(context).helloWorld;
}

The getter 'helloWorld' was called on null.
Receiver: null
Tried calling: helloWorld

Ответить
Qais Nezami
Qais Nezami - 17.12.2021 19:53

A value of type 'Null' can't be assigned to a variable of type 'Locale'.

Ответить
Lynixis Bleysed
Lynixis Bleysed - 06.12.2021 13:32

Hello, thanks for this awesome tutorial, i tried your tuto, but I have problem,
after each restart of app, it's give me the default locale, how i can save the selected language and use it ?

Ответить
Gumdum
Gumdum - 05.12.2021 03:33

Thank you very much for this! Easy to follow instructions on the latest way to handle localization.

Ответить
Udit Mishra
Udit Mishra - 16.11.2021 20:26

Very useful video,
Thanks.

Ответить
JohnLiuFromHK
JohnLiuFromHK - 05.11.2021 07:20

Hello, i want to ask sth about the arb file.
As I have to generate language for simplified chinese which requires a locale with country code. But then when I build the project, an error told me I have to create a base arb file. So i have app_zh.arb and app_zh_CN.arb.

But inside the generated files, I can only find the app_localizations_zh.dart. Do you know what am i missing?

Ответить
Allen Richard Yeager
Allen Richard Yeager - 01.11.2021 15:47

Your tutorial save my life. thank you

Ответить
Suman Baul
Suman Baul - 31.10.2021 00:20

Hi Johannas, Great tutorial.
Can you please make a tutorial for reading and opening all app notifications. It will be very helpful.
Thanks.

Ответить
slvn klvra
slvn klvra - 18.10.2021 00:52

Great tutorial! But I've got this error :"Exception has occurred.
_CastError (Null check operator used on a null value)" .Flutter suggest to add "!" like this "AppLocalizations.of(context)!.appName " but it generates the error.Did you had it?

Ответить
Tarik ali
Tarik ali - 13.10.2021 18:56

Good but there is no israel , it's palestine

Ответить
Pedro Santos
Pedro Santos - 03.10.2021 23:56

Thanks mate!

Ответить
Jeffrey Liu
Jeffrey Liu - 19.09.2021 08:04

This is great thank you. Can you teach us how to save the language preference in shared pref so load up would work? Now with your code I believe once we kill the app, it will reset back to default system local. If you save the local, then loading local from shared pref would be async and it would be slow on app start up.

Ответить
Satish Dhend
Satish Dhend - 19.09.2021 07:25

You are great👍😊👏

Ответить
Developer Buddy
Developer Buddy - 04.09.2021 21:56

Please Brother,
Make series on Bloc

Ответить
Blue Inc
Blue Inc - 03.09.2021 20:56

I love your videos Man . However i face some issue about The getter 'value' was called on null

Ответить
RAKESH SINGH RAWAT
RAKESH SINGH RAWAT - 01.09.2021 13:46

sir if my mobile default language is english but i want to show spanish language first time i open the app

Ответить