flutter 다국어 설정

 

Flutter 다국어 설정


라이브러리 추가

dependencies:
  flutter_localizations:
    sdk: flutter

  intl: ^0.19.0

flutter:
  uses-material-design: true
  generate: true

main.dart (MaterialApp 설정)

localizationsDelegates: const [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    // 커스텀 로컬라이제이션 delegate 추가
    AppLocalizations.delegate,
],
supportedLocales: const [
    Locale('en', ''), // 영어
    Locale('ko', ''), // 한국어
    // 필요한 다른 언어 추가
],

설정 파일

[/l10n.yaml]
arb-dir: lib/l10n
template-arb-file: app_ko.arb

# 생성된 코드가 어디로 가야하는지
output-localization-file: app_localizations.dart
preferred-supported-locales:
  - en
  - ko
use-deferred-loading: true
suppress-warnings: true
output-class: AppLocalizations

[/lib/l10n/app_en.arb, app_ko.arb]
{
"@@locale": "en",
"appTitle": "App Title"
}
{
"@@locale": "ko",
"appTitle": "앱 제목", }

다국어(로컬라이제이션) 파일 생성

$ flutter gen-l10n



댓글