Today 요약
[✅] 프로그래머스 코딩테스트 2문제
[✅] flutter 강의 2개
배운 점
1) flutter 번역
1-1 pubspec.yaml 추가
flutter :
generate: true
- 추후 코드 생성하는데 도움을 준다
1-2 l10n.yaml 생성
arb-dir: lib/intl
template-arb-file: intl_en.arb
output-localization-file: intl_generated.dart
- 번역파일의 확장자는 .arb
- arb-dir : 번역파일이 어디에 위치해 있는지
- template-arb-file: 마스터 파일이 무엇인지? 현재개발언어 name_언어코드.arb로 작성
- output-localization-file : 번역본 파일이 어느곳에 생성되어야하는지
1-3 lib 안에 파일 생성
- 폴더 intl
- intl 내에 intl_en.arb 와 intl_ko.arb 생성
1-4 flutter intl 확장 프로그램 다운
1-5 intl_en.arb와 intl_ko.arb 내 각각 작성
{
"signUpTitle": "Sign up for {nameOfTheApp}",
}
{
"signUpTitle": "{nameOfTheApp}에 가입하세요"
}
1-6 터미널 작성
flutter gen-l10n
1-7 .dart_tool > flutter_gen > intl_generated.dart 생성 확인하기
1-8 main.dart 수정
import 'package:flutter_gen/gen_l10n/intl_generated.dart';
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
)
- localizationDelegates: 현지화 위젯에 대한 모든 현지화된 리소스를 집학접으로 정의
- AppLocalizations.delegate 의 장점 : supportedLocales의 리스트도 함께 제공
- supportedLocales : 현지화된 로케일 목록
localizationsDelegates property - MaterialApp class - material library - Dart API
Iterable ? localizationsDelegates final The delegates for this app's Localizations widget. The delegates collectively define all of the localized resources for this application's Localizations widget. Internationalized apps that require translations for on
api.flutter.dev
supportedLocales property - CupertinoApp class - cupertino library - Dart API
Iterable supportedLocales final The list of locales that this app has been localized for. By default only the American English locale is supported. Apps should configure this list to match the locales they support. This list must not null. Its default valu
api.flutter.dev
1-9 번역돌릴 텍스트 수정
import 'package:flutter_gen/gen_l10n/intl_generated.dart';
Text(
AppLocalizations.of(context).signUpTitle,
)
- 앱의 언어에 따라 영문, 한글로 표시 된다
1-10 번역 placeholder 설명
{
"signUpTitle": "Sign up for {nameOfTheApp}",
"@signUpTitle": {
"description": "The title people see when they open the app for the first time.",
"placeholders": {
"nameOfTheApp": {
"type": "String",
"example": "TestApp"
}
}
}
}
- intl_en.arb 파일을 위와 같이 수정한후 Text도 아래와 같이수정해준다
Text(
AppLocalizations.of(context)!.signUpTitle("TestApp"),
),
- signUptitle에 마우스를 올려보면 아래와 같은 설명이 나온다
String signUpTitle(String nameOfTheApp)
Type: String Function(String)
package:flutter_gen/gen_l10n/intl_generated.dart
The title people see when they open the app for the first time.
In en, this message translates to: 'Sign up for {nameOfTheApp}'
최근에 react 파일 번역한게 생각이 나기도 하고.. ! 오늘도 공부를 하기는 했다!! 뿌듯
'TIL' 카테고리의 다른 글
20230826 TIL (1) | 2023.08.26 |
---|---|
20230823 TIL (1) | 2023.08.23 |
20230821 TIL (0) | 2023.08.21 |
20230820 TIL (0) | 2023.08.20 |
20230819 TIL (0) | 2023.08.19 |