Skip to content

Commit

Permalink
feat: strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jul 10, 2024
1 parent 0cc58e9 commit c664c57
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 50 deletions.
14 changes: 8 additions & 6 deletions lib/loaders/e2e_file_translation_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:async';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_i18n/loaders/decoders/base_decode_strategy.dart';
import 'package:flutter/widgets.dart';

import 'file_translation_loader.dart';

Expand All @@ -19,12 +21,12 @@ class E2EFileTranslationLoader extends FileTranslationLoader {
AssetBundle customAssetBundle = _CustomAssetBundle();

E2EFileTranslationLoader(
{forcedLocale,
fallbackFile = "en",
basePath = "assets/flutter_i18n",
useCountryCode = false,
this.useE2E = true,
decodeStrategies})
{Locale? forcedLocale,
String? fallbackFile = "en",
String basePath = "assets/flutter_i18n",
bool useCountryCode = false,
bool this.useE2E = true,
List<BaseDecodeStrategy>? decodeStrategies})
: super(
fallbackFile: fallbackFile,
basePath: basePath,
Expand Down
14 changes: 7 additions & 7 deletions lib/loaders/file_translation_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class FileTranslationLoader extends TranslationLoader implements IFileContent {
];

FileTranslationLoader(
{this.fallbackFile = "en",
this.basePath = "assets/flutter_i18n",
this.separator = "_",
this.useCountryCode = false,
this.useScriptCode = false,
forcedLocale,
decodeStrategies}) {
{String? this.fallbackFile = "en",
String this.basePath = "assets/flutter_i18n",
String this.separator = "_",
bool this.useCountryCode = false,
bool this.useScriptCode = false,
Locale? forcedLocale,
List<BaseDecodeStrategy>? decodeStrategies}) {
this.forcedLocale = forcedLocale;
this.decodeStrategies = decodeStrategies;
}
Expand Down
12 changes: 7 additions & 5 deletions lib/loaders/local_translation_loader.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'dart:io';

import 'package:flutter/widgets.dart';
import 'package:flutter_i18n/loaders/decoders/base_decode_strategy.dart';
import 'package:flutter_i18n/loaders/file_translation_loader.dart';

class LocalTranslationLoader extends FileTranslationLoader {
LocalTranslationLoader(
{basePath = "assets/flutter_i18n",
useCountryCode = false,
useScriptCode = false,
forcedLocale,
decodeStrategies})
{String basePath = "assets/flutter_i18n",
bool useCountryCode = false,
bool useScriptCode = false,
Locale? forcedLocale,
List<BaseDecodeStrategy>? decodeStrategies})
: super(
basePath: basePath,
useCountryCode: useCountryCode,
Expand Down
18 changes: 10 additions & 8 deletions lib/loaders/namespace_file_translation_loader.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_i18n/loaders/decoders/base_decode_strategy.dart';
import 'package:flutter_i18n/loaders/file_translation_loader.dart';
import 'package:flutter_i18n/utils/message_printer.dart';

Expand All @@ -11,14 +13,14 @@ class NamespaceFileTranslationLoader extends FileTranslationLoader {
Map<dynamic, dynamic> _decodedMap = {};

NamespaceFileTranslationLoader(
{required this.namespaces,
this.fallbackDir = "en",
basePath = "assets/flutter_i18n",
separator = "_",
useCountryCode = false,
useScriptCode = false,
forcedLocale,
decodeStrategies})
{required List<String>? this.namespaces,
String this.fallbackDir = "en",
String basePath = "assets/flutter_i18n",
String separator = "_",
bool useCountryCode = false,
bool useScriptCode = false,
Locale? forcedLocale,
List<BaseDecodeStrategy>? decodeStrategies})
: super(
basePath: basePath,
separator: separator,
Expand Down
16 changes: 9 additions & 7 deletions lib/loaders/network_file_translation_loader.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:flutter_i18n/loaders/decoders/base_decode_strategy.dart';
import 'package:http/http.dart' as http;

import 'file_translation_loader.dart';
Expand All @@ -9,13 +11,13 @@ class NetworkFileTranslationLoader extends FileTranslationLoader {
final Uri baseUri;

NetworkFileTranslationLoader(
{required this.baseUri,
forcedLocale,
fallbackFile = "en",
separator = "_",
useCountryCode = false,
useScriptCode = false,
decodeStrategies})
{required Uri this.baseUri,
Locale? forcedLocale,
String fallbackFile = "en",
String separator = "_",
bool useCountryCode = false,
bool useScriptCode = false,
List<BaseDecodeStrategy>? decodeStrategies})
: super(
fallbackFile: fallbackFile,
separator: separator,
Expand Down
35 changes: 18 additions & 17 deletions test/test_loader.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_i18n/loaders/decoders/toml_decode_strategy.dart';
import 'package:flutter_i18n/loaders/decoders/xml_decode_strategy.dart';
import 'package:flutter_i18n/loaders/decoders/yaml_decode_strategy.dart';
import 'package:flutter_i18n/loaders/decoders/toml_decode_strategy.dart';

Future<String> _loadString(String fileName, String extension) async {
if (fileName.contains('_en')) {
Expand Down Expand Up @@ -31,10 +32,10 @@ Future<String> _loadString(String fileName, String extension) async {

class TestJsonLoader extends FileTranslationLoader {
TestJsonLoader({
forcedLocale,
fallbackFile = "en",
basePath = "assets/flutter_i18n",
useCountryCode = false,
Locale? forcedLocale,
String fallbackFile = "en",
String basePath = "assets/flutter_i18n",
bool useCountryCode = false,
}) : super(
fallbackFile: fallbackFile,
basePath: basePath,
Expand All @@ -49,10 +50,10 @@ class TestJsonLoader extends FileTranslationLoader {

class TestYamlLoader extends FileTranslationLoader {
TestYamlLoader({
forcedLocale,
fallbackFile = "en",
basePath = "assets/flutter_i18n",
useCountryCode = false,
Locale? forcedLocale,
String fallbackFile = "en",
String basePath = "assets/flutter_i18n",
bool useCountryCode = false,
}) : super(
fallbackFile: fallbackFile,
basePath: basePath,
Expand All @@ -77,10 +78,10 @@ class TestYamlLoader extends FileTranslationLoader {

class TestTomlLoader extends FileTranslationLoader {
TestTomlLoader({
forcedLocale,
fallbackFile = "en",
basePath = "assets/flutter_i18n",
useCountryCode = false,
Locale? forcedLocale,
String fallbackFile = "en",
String basePath = "assets/flutter_i18n",
bool useCountryCode = false,
}) : super(
fallbackFile: fallbackFile,
basePath: basePath,
Expand All @@ -105,10 +106,10 @@ class TestTomlLoader extends FileTranslationLoader {

class TestXmlLoader extends FileTranslationLoader {
TestXmlLoader({
forcedLocale,
fallbackFile = "en",
basePath = "assets/flutter_i18n",
useCountryCode = false,
Locale? forcedLocale,
String fallbackFile = "en",
String basePath = "assets/flutter_i18n",
bool useCountryCode = false,
}) : super(
fallbackFile: fallbackFile,
basePath: basePath,
Expand Down

0 comments on commit c664c57

Please sign in to comment.