패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소Innim/flutter_multiple_localization

flutter_multiple_localization

Flutter 다국어 패키지

flutter_multiple_localization 프로젝트 이미지
스타
16
포크
22
최근 푸시(UTC)
2025. 6. 12.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

multiple_localization

pub package Analyze & Test innim lint

Support for multiple abr and messages localization files for intl package.

Problem

If you want to have multiple arb files and register separate delegate for each one of them, then you have a problem. Intl doesn't allow multiple initializeMessages calls. Only first one will be processed and only it's messages will be used. Every calls after the first one will be ignored.

Why do we need to have multiple arb files?

In common scenario - we don't. Just put all localization string in single file and enjoy. But if you want to add intl localization with arb files to separate package, and than use it in you project with it's own localization files - that's problem.

MultipleLocalizations supports using Localizations.override(delegates: [SomeLocalizationsDelegate(), ...]) widget, too.

Exactly for that situation this package was developed.

See article on Medium for more details - Localization for Dart package.

Usage

To use this package, add multiple_localization as a dependency in your pubspec.yaml file.

Than use MultipleLocalizations.load for your delegate load function, instead of call initializeMessages explicitly.

Example
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
  const _AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) {
    return ['en', 'ru'].contains(locale.languageCode);
  }

  @override
  Future<AppLocalizations> load(Locale locale) {
    return MultipleLocalizations.load(
        initializeMessages, locale, (l) => AppLocalizations(l),
        setDefaultLocale: true);
  }

  @override
  bool shouldReload(LocalizationsDelegate<AppLocalizations> old) {
    return false;
  }
}
Override string from package in project

If you want to override string from package localization in project (for example to change some labels in package widgets) - you need to define string with required name in you app localization class.

Example.

If package has string messageFromPackageForOverride:

class PackageLocalizations {
  ...

  String get messageFromPackageForOverride =>
        Intl.message('Package', name: 'messageFromPackageForOverride');

Then you need to define messageFromPackageForOverride in you AppLocalizations:

class AppLocalizations {
  ...

  String get messageFromPackageForOverride =>
        Intl.message('App', name: 'messageFromPackageForOverride');

Make sure that you add the app localization delegate before the package localization delegate:

  ...
  const MaterialApp(
    localizationsDelegates: [
      AppLocalizations.delegate,
      PackageLocalizations.delegate,
      ...
    ],
    ...

Now, whenever package use messageFromPackageForOverride you will see App, not Package.

Set fallback locale

Also you can specify a fallback locale when loading application localization delegate. Use [fallbackLocale] parameter to set locale which will be used if some key not found for current locale. Only first call of [load] will set fallback locale, make sure that your app's localization delegate added as a first element of the delegates list.

Also pay attention that if you provide the [fallbackLocale], than all messages will be uploaded in memory on the start of application in addition to current locale.

Innim GitHub avatar
GitHub 작성자

Innim ↗

Developing mobile apps, web services and games

언어DartSwiftKotlinObjective-C

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 4 개

  • flutter{"sdk":"flutter"}
  • intl^0.20.0
  • flutter_test개발 의존성{"sdk":"flutter"}
  • innim_lint개발 의존성^0.5.0+1

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗