@jonataslaw I can't able to update the locale when the system language is changed.I haven't able to see the reference of how to implement in the documantation.Please help me how to implement this.
@jonataslaw please help me regarding this
@jonataslaw any update regarding this?
coincidence or not, there is a pull requests that is adding a little bit more docs of how to make internationalization work.
https://github.com/jonataslaw/getx/pull/601
Maybe you won't find you answer there, but maybe you will 馃槄
The translation comes down to adding a ".tr" to the end of your String, and changing the locale with Get.changeLocale.
follow the example:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(GetMaterialApp(
initialRoute: '/home',
translations: MyTranslations(),
locale: Locale('pt', 'BR'), // insert initial locale
getPages: [
GetPage(name: '/home', page: () => First()),
],
));
}
class First extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("title".trArgs(['John'])), // use String.tr or String.trArgs
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
child: Text('Change locale to English'),
onPressed: () {
Get.updateLocale(Locale('en', 'UK')); // update locale
},
),
],
),
),
);
}
}
class MyTranslations extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'en': {
'title': 'Hello World %s',
},
'en_US': {
'title': 'Hello World from US',
},
'pt': {
'title': 'Ol谩 de Portugal',
},
'pt_BR': {
'title': 'Ol谩 do Brasil',
},
};
}
Next time, use the platform channels to answer questions, as it is the most appropriate channel and you will be answered more quickly.
Most helpful comment
@jonataslaw any update regarding this?