Open name27 opened 1 year ago
return GetMaterialApp( ..... translations: Languages(), ..... );
import 'package:get/get.dart';
class Languages extends Translations { @override Map<String, Map<String, String>> get keys => { 'ko_KR': { 'greeting': '안녕하세요', }, 'ja_JP': { 'greeting': 'こんにちは', }, 'en_US': { 'greeting': 'Hello', }, }; }
4. 실제 사용 예시
return GetMaterialApp( .... locale: Get.deviceLocale, //Get.deviceLocale장치 언어를 얻기 .... );
GetMaterialApp( ... fallbackLocale: const Locale('en', 'US'), //기본 언어를 표시 ... );
class MyHomePage extends StatelessWidget { const MyHomePage({Key? key}) : super(key: key);
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'greeting'.tr, //tr 현지화된 메시지를 표시 style: Theme.of(context).textTheme.headline4, ), OutlinedButton( onPressed: () => Get.updateLocale(const Locale('ko', 'KR')), //언어변경 child: const Text('Korean'), ), ], ), ), ); } }
i18n
class Languages extends Translations { @override Map<String, Map<String, String>> get keys => { 'ko_KR': { 'greeting': '안녕하세요', }, 'ja_JP': { 'greeting': 'こんにちは', }, 'en_US': { 'greeting': 'Hello', }, }; }
return GetMaterialApp( .... locale: Get.deviceLocale, //Get.deviceLocale장치 언어를 얻기 .... );
GetMaterialApp( ... fallbackLocale: const Locale('en', 'US'), //기본 언어를 표시 ... );
class MyHomePage extends StatelessWidget { const MyHomePage({Key? key}) : super(key: key);
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'greeting'.tr, //tr 현지화된 메시지를 표시 style: Theme.of(context).textTheme.headline4, ), OutlinedButton( onPressed: () => Get.updateLocale(const Locale('ko', 'KR')), //언어변경 child: const Text('Korean'), ), ], ), ), ); } }