-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created feature localizations - Created Delegates - Refactored folder structure a bit
- Loading branch information
1 parent
d16d503
commit 42f6293
Showing
26 changed files
with
134 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ build/ | |
# Codegen | ||
*.*.dart | ||
generated_* | ||
lib/src/core/localization/generated/ | ||
|
||
pubspec.lock | ||
.metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
include: package:sizzle_lints/sizzle_lints.yaml | ||
include: package:sizzle_lints/sizzle_lints.yaml | ||
|
||
analyzer: | ||
exclude: | ||
- "lib/src/core/localization/generated/**" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
arb-dir: lib/src/core/localization | ||
arb-dir: lib/src/core/localization/translations | ||
template-arb-file: app_en.arb | ||
output-localization-file: app_localizations.dart | ||
output-localization-file: generated_localizations.dart | ||
output-class: GeneratedLocalizations | ||
output-dir: lib/src/core/localization/generated | ||
nullable-getter: false | ||
synthetic-package: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:sizzle_starter/src/core/localization/generated/generated_localizations.dart'; | ||
import 'package:sizzle_starter/src/core/localization/localization_delegate.dart'; | ||
import 'package:sizzle_starter/src/feature/sample/localization/sample_localization_delegate.dart'; | ||
|
||
/// A class which is responsible for providing the localization. | ||
/// | ||
/// [AppLocalization] is a wrapper around [AppLocalizations]. | ||
/// | ||
/// [AppLocalization] is a wrapper around [GeneratedLocalizations]. | ||
class AppLocalization { | ||
AppLocalization._(); | ||
|
||
static AppLocalizations of(BuildContext context) => AppLocalizations.of(context)!; | ||
/// All the supported locales | ||
/// | ||
/// SSOT - arb files | ||
static const supportedLocales = GeneratedLocalizations.supportedLocales; | ||
|
||
/// All the localizations delegates | ||
static final localizationsDelegates = <LocalizationsDelegate<dynamic>>[ | ||
...GeneratedLocalizations.localizationsDelegates, | ||
...featureDelegates, | ||
]; | ||
|
||
/// Feature localization delegates | ||
static final featureDelegates = <LocalizationDelegate<Object>>[ | ||
SampleLocalizationDelegate(), | ||
]; | ||
|
||
/// Returns the localized strings for the given [context]. | ||
static T stringOf<T>(BuildContext context) => Localizations.of<T>(context, T)!; | ||
|
||
static const supportedLocales = AppLocalizations.supportedLocales; | ||
/// Returns the current locale of the [context]. | ||
static Locale? localeOf(BuildContext context) => Localizations.localeOf(context); | ||
|
||
static const localizationsDelegates = AppLocalizations.localizationsDelegates; | ||
/// Loads the [locale]. | ||
static Future<GeneratedLocalizations> load(Locale locale) => | ||
GeneratedLocalizations.delegate.load(locale); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:sizzle_starter/src/core/localization/generated/generated_localizations.dart'; | ||
|
||
abstract class LocalizationDelegate<T> extends LocalizationsDelegate<T> { | ||
LocalizationDelegate(this._delegateFactory); | ||
|
||
final T Function(GeneratedLocalizations appLocalizations) _delegateFactory; | ||
|
||
@override | ||
Future<T> load(Locale locale) async { | ||
final appLocalizations = await GeneratedLocalizations.delegate.load(locale); | ||
return _delegateFactory(appLocalizations); | ||
} | ||
|
||
@override | ||
bool shouldReload(covariant LocalizationsDelegate<T> old) => false; | ||
|
||
@override | ||
bool isSupported(Locale locale) => GeneratedLocalizations.delegate.isSupported(locale); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"appTitle": "sizzle_starter", | ||
"@appTitle": { | ||
"description": "The title of the application" | ||
}, | ||
"samplePlaceholder": "Sample placeholder {value}", | ||
"@samplePlaceholder": { | ||
"description": "Sample placeholder" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"appTitle": "sizzle_starter", | ||
"@appTitle": { | ||
"description": "El título de la aplicación" | ||
}, | ||
"samplePlaceholder": "Espacio reservado de muestra {value}", | ||
"@samplePlaceholder": { | ||
"description": "Espacio reservado de muestra" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
extension LocalizationX on BuildContext { | ||
T stringOf<T>() => Localizations.of<T>(this, T)!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/src/feature/initialization/logic/initialization_processor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
lib/src/core/model/environment_store.dart → ...itialization/model/environment_store.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
lib/src/feature/sample/localization/sample_localization_delegate.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:sizzle_starter/src/core/localization/generated/generated_localizations.dart'; | ||
import 'package:sizzle_starter/src/core/localization/localization_delegate.dart'; | ||
|
||
abstract class SampleStrings { | ||
String get appTitle; | ||
|
||
String samplePlaceholder(String value); | ||
} | ||
|
||
class SampleLocalizationDelegate extends LocalizationDelegate<SampleStrings> { | ||
SampleLocalizationDelegate() : super(_SampleStringsImpl.new); | ||
} | ||
|
||
class _SampleStringsImpl implements SampleStrings { | ||
_SampleStringsImpl(this._appLocalizations); | ||
|
||
final GeneratedLocalizations _appLocalizations; | ||
|
||
@override | ||
String get appTitle => _appLocalizations.appTitle; | ||
|
||
@override | ||
String samplePlaceholder(String value) => _appLocalizations.samplePlaceholder(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters