diff --git a/slang/README.md b/slang/README.md index 2975ae73..0a32e08a 100644 --- a/slang/README.md +++ b/slang/README.md @@ -290,6 +290,7 @@ flutter_integration: true namespaces: false translate_var: t enum_name: AppLocale +class_name: Translations translation_class_visibility: private key_case: snake key_map_case: camel @@ -359,6 +360,7 @@ targets: namespaces: false translate_var: t enum_name: AppLocale + class_name: Translations translation_class_visibility: private key_case: snake key_map_case: camel @@ -405,42 +407,42 @@ targets: -| Key | Type | Usage | Default | -|-------------------------------------|------------------------------------|--------------------------------------------------------------|---------------| -| `base_locale` | `String` | locale of default json | `en` | -| `fallback_strategy` | `none`, `base_locale` | handle missing translations [(i)](#-fallback) | `none` | -| `input_directory` | `String` | path to input directory | `null` | -| `input_file_pattern` | `String` | input file pattern, must end with .json, .yaml or .csv | `.i18n.json` | -| `output_directory` | `String` | path to output directory | `null` | -| `output_file_name` | `String` | output file name | `null` | -| `output_format` | `single_file`, `multiple_files` | split output files [(i)](#-output-format) | `single_file` | -| `locale_handling` | `Boolean` | generate locale handling logic [(i)](#-dependency-injection) | `true` | -| `flutter_integration` | `Boolean` | generate flutter features [(i)](#-dart-only) | `true` | -| `namespaces` | `Boolean` | split input files [(i)](#-namespaces) | `false` | -| `translate_var` | `String` | translate variable name | `t` | -| `enum_name` | `String` | enum name | `AppLocale` | -| `translation_class_visibility` | `private`, `public` | class visibility | `private` | -| `key_case` | `null`, `camel`, `pascal`, `snake` | transform keys (optional) [(i)](#-recasing) | `null` | -| `key_map_case` | `null`, `camel`, `pascal`, `snake` | transform keys for maps (optional) [(i)](#-recasing) | `null` | -| `param_case` | `null`, `camel`, `pascal`, `snake` | transform parameters (optional) [(i)](#-recasing) | `null` | -| `string_interpolation` | `dart`, `braces`, `double_braces` | string interpolation mode [(i)](#-string-interpolation) | `dart` | -| `flat_map` | `Boolean` | generate flat map [(i)](#-dynamic-keys--flat-map) | `true` | -| `translation_overrides` | `Boolean` | enable translation overrides [(i)](#-translation-overrides) | `false` | -| `timestamp` | `Boolean` | write "Built on" timestamp | `true` | -| `maps` | `List` | entries which should be accessed via keys [(i)](#-maps) | `[]` | -| `pluralization`/`auto` | `off`, `cardinal`, `ordinal` | detect plurals automatically [(i)](#-pluralization) | `cardinal` | -| `pluralization`/`default_parameter` | `String` | default plural parameter [(i)](#-pluralization) | `n` | -| `pluralization`/`cardinal` | `List` | entries which have cardinals | `[]` | -| `pluralization`/`ordinal` | `List` | entries which have ordinals | `[]` | -| ``/`enum` | `List` | DEPRECATED: context forms [(i)](#-custom-contexts--enums) | no default | -| ``/`paths` | `List` | DEPRECATED: entries using this context | `[]` | -| ``/`default_parameter` | `String` | default parameter name | `context` | -| ``/`generate_enum` | `Boolean` | generate enum | `true` | -| `children of interfaces` | `Pairs of Alias:Path` | alias interfaces [(i)](#-interfaces) | `null` | -| `obfuscation`/`enabled` | `Boolean` | enable obfuscation [(i)](#-obfuscation) | `false` | -| `obfuscation`/`secret` | `String` | obfuscation secret (random if null) [(i)](#-obfuscation) | `null` | -| `imports` | `List` | generate import statements | `[]` | -| `class_name` | `String` | name of the translations class | `Translations`| +| Key | Type | Usage | Default | +|-------------------------------------|------------------------------------|--------------------------------------------------------------|----------------| +| `base_locale` | `String` | locale of default json | `en` | +| `fallback_strategy` | `none`, `base_locale` | handle missing translations [(i)](#-fallback) | `none` | +| `input_directory` | `String` | path to input directory | `null` | +| `input_file_pattern` | `String` | input file pattern, must end with .json, .yaml or .csv | `.i18n.json` | +| `output_directory` | `String` | path to output directory | `null` | +| `output_file_name` | `String` | output file name | `null` | +| `output_format` | `single_file`, `multiple_files` | split output files [(i)](#-output-format) | `single_file` | +| `locale_handling` | `Boolean` | generate locale handling logic [(i)](#-dependency-injection) | `true` | +| `flutter_integration` | `Boolean` | generate flutter features [(i)](#-dart-only) | `true` | +| `namespaces` | `Boolean` | split input files [(i)](#-namespaces) | `false` | +| `translate_var` | `String` | translate variable name | `t` | +| `enum_name` | `String` | enum name | `AppLocale` | +| `class_name` | `String` | name of the translations class | `Translations` | +| `translation_class_visibility` | `private`, `public` | class visibility | `private` | +| `key_case` | `null`, `camel`, `pascal`, `snake` | transform keys (optional) [(i)](#-recasing) | `null` | +| `key_map_case` | `null`, `camel`, `pascal`, `snake` | transform keys for maps (optional) [(i)](#-recasing) | `null` | +| `param_case` | `null`, `camel`, `pascal`, `snake` | transform parameters (optional) [(i)](#-recasing) | `null` | +| `string_interpolation` | `dart`, `braces`, `double_braces` | string interpolation mode [(i)](#-string-interpolation) | `dart` | +| `flat_map` | `Boolean` | generate flat map [(i)](#-dynamic-keys--flat-map) | `true` | +| `translation_overrides` | `Boolean` | enable translation overrides [(i)](#-translation-overrides) | `false` | +| `timestamp` | `Boolean` | write "Built on" timestamp | `true` | +| `maps` | `List` | entries which should be accessed via keys [(i)](#-maps) | `[]` | +| `pluralization`/`auto` | `off`, `cardinal`, `ordinal` | detect plurals automatically [(i)](#-pluralization) | `cardinal` | +| `pluralization`/`default_parameter` | `String` | default plural parameter [(i)](#-pluralization) | `n` | +| `pluralization`/`cardinal` | `List` | entries which have cardinals | `[]` | +| `pluralization`/`ordinal` | `List` | entries which have ordinals | `[]` | +| ``/`enum` | `List` | DEPRECATED: context forms [(i)](#-custom-contexts--enums) | no default | +| ``/`paths` | `List` | DEPRECATED: entries using this context | `[]` | +| ``/`default_parameter` | `String` | default parameter name | `context` | +| ``/`generate_enum` | `Boolean` | generate enum | `true` | +| `children of interfaces` | `Pairs of Alias:Path` | alias interfaces [(i)](#-interfaces) | `null` | +| `obfuscation`/`enabled` | `Boolean` | enable obfuscation [(i)](#-obfuscation) | `false` | +| `obfuscation`/`secret` | `String` | obfuscation secret (random if null) [(i)](#-obfuscation) | `null` | +| `imports` | `List` | generate import statements | `[]` | ## Main Features @@ -1042,7 +1044,7 @@ Example using the `riverpod` library: ```dart final english = AppLocale.en.build(cardinalResolver: myEnResolver); final german = AppLocale.de.build(cardinalResolver: myDeResolver); -final translationProvider = StateProvider((ref) => german); // set it +final translationProvider = StateProvider((ref) => german); // set it // access the current instance final t = ref.watch(translationProvider); diff --git a/slang/documentation/dependency_injection.md b/slang/documentation/dependency_injection.md index 4747e81f..fb470b87 100644 --- a/slang/documentation/dependency_injection.md +++ b/slang/documentation/dependency_injection.md @@ -29,7 +29,7 @@ Here is an example using the `riverpod` package. ```dart final english = AppLocale.en.build(); final german = AppLocale.de.build(); -final translationProvider = StateProvider((ref) => german); // set it +final translationProvider = StateProvider((ref) => german); // set it // access the current instance final t = ref.watch(translationProvider); @@ -49,11 +49,11 @@ To make things easier, there are some utility functions in `AppLocaleUtils`. ```dart // get locale as enum -final AppLocale deviceLocale = AppLocaleUtils.findDeviceLocale(); -final AppLocale specificLocale = AppLocaleUtils.parse('en_US'); // handles '-' and '_' +AppLocale deviceLocale = AppLocaleUtils.findDeviceLocale(); +AppLocale specificLocale = AppLocaleUtils.parse('en_US'); // handles '-' and '_' // build instance -final StringsEn translations = specificLocale.build(); +Translations translations = specificLocale.build(); // access instance AppLocale locale = translations.$meta.locale; diff --git a/slang/lib/builder/builder/generate_config_builder.dart b/slang/lib/builder/builder/generate_config_builder.dart index e506d62c..bc936341 100644 --- a/slang/lib/builder/builder/generate_config_builder.dart +++ b/slang/lib/builder/builder/generate_config_builder.dart @@ -23,6 +23,7 @@ class GenerateConfigBuilder { flutterIntegration: config.flutterIntegration, translateVariable: config.translateVar, enumName: config.enumName, + className: config.className, translationClassVisibility: config.translationClassVisibility, renderFlatMap: config.renderFlatMap, translationOverrides: config.translationOverrides, @@ -37,7 +38,6 @@ class GenerateConfigBuilder { interface: interfaces, obfuscation: config.obfuscation, imports: config.imports, - className: config.className, ); } } diff --git a/slang/lib/builder/builder/raw_config_builder.dart b/slang/lib/builder/builder/raw_config_builder.dart index b209c4ca..b4abd344 100644 --- a/slang/lib/builder/builder/raw_config_builder.dart +++ b/slang/lib/builder/builder/raw_config_builder.dart @@ -71,6 +71,7 @@ class RawConfigBuilder { namespaces: map['namespaces'] ?? RawConfig.defaultNamespaces, translateVar: map['translate_var'] ?? RawConfig.defaultTranslateVar, enumName: map['enum_name'] ?? RawConfig.defaultEnumName, + className: map['class_name'] ?? RawConfig.defaultClassName, translationClassVisibility: (map['translation_class_visibility'] as String?) ?.toTranslationClassVisibility() ?? @@ -107,7 +108,6 @@ class RawConfigBuilder { ?.toObfuscationConfig() ?? RawConfig.defaultObfuscationConfig, imports: map['imports']?.cast() ?? RawConfig.defaultImports, - className: map['class_name'] ?? RawConfig.defaultClassName, rawMap: map, ); } diff --git a/slang/lib/builder/model/generate_config.dart b/slang/lib/builder/model/generate_config.dart index 4ebb678c..be0e5334 100644 --- a/slang/lib/builder/model/generate_config.dart +++ b/slang/lib/builder/model/generate_config.dart @@ -18,6 +18,7 @@ class GenerateConfig { final bool flutterIntegration; final String translateVariable; final String enumName; + final String className; final TranslationClassVisibility translationClassVisibility; final bool renderFlatMap; final bool translationOverrides; @@ -26,7 +27,6 @@ class GenerateConfig { final List interface; // may include more than in build config final ObfuscationConfig obfuscation; final List imports; - final String className; GenerateConfig({ required this.buildConfig, @@ -39,6 +39,7 @@ class GenerateConfig { required this.flutterIntegration, required this.translateVariable, required this.enumName, + required this.className, required this.translationClassVisibility, required this.renderFlatMap, required this.translationOverrides, @@ -47,6 +48,5 @@ class GenerateConfig { required this.interface, required this.obfuscation, required this.imports, - required this.className, }); } diff --git a/slang/lib/builder/model/raw_config.dart b/slang/lib/builder/model/raw_config.dart index 36c448d6..35fb078a 100644 --- a/slang/lib/builder/model/raw_config.dart +++ b/slang/lib/builder/model/raw_config.dart @@ -18,6 +18,7 @@ class RawConfig { static const bool defaultNamespaces = false; static const String defaultTranslateVar = 't'; static const String defaultEnumName = 'AppLocale'; + static const String defaultClassName = 'Translations'; static const TranslationClassVisibility defaultTranslationClassVisibility = TranslationClassVisibility.private; static const CaseStyle? defaultKeyCase = null; @@ -38,7 +39,6 @@ class RawConfig { static final ObfuscationConfig defaultObfuscationConfig = ObfuscationConfig.disabled(); static const List defaultImports = []; - static const String defaultClassName = 'Translations'; final FileType fileType; final I18nLocale baseLocale; @@ -53,6 +53,7 @@ class RawConfig { final bool namespaces; final String translateVar; final String enumName; + final String className; final TranslationClassVisibility translationClassVisibility; final CaseStyle? keyCase; final CaseStyle? keyMapCase; @@ -70,7 +71,6 @@ class RawConfig { final List interfaces; final ObfuscationConfig obfuscation; final List imports; - final String className; /// Used by external tools to access the raw config. (e.g. slang_gpt) final Map rawMap; @@ -88,6 +88,7 @@ class RawConfig { required this.namespaces, required this.translateVar, required this.enumName, + required this.className, required this.translationClassVisibility, required this.keyCase, required this.keyMapCase, @@ -105,7 +106,6 @@ class RawConfig { required this.interfaces, required this.obfuscation, required this.imports, - required this.className, required this.rawMap, }) : fileType = _determineFileType(inputFilePattern); @@ -143,6 +143,7 @@ class RawConfig { namespaces: namespaces ?? this.namespaces, translateVar: translateVar, enumName: enumName, + className: className, translationClassVisibility: translationClassVisibility, keyCase: keyCase ?? this.keyCase, keyMapCase: keyMapCase ?? this.keyMapCase, @@ -160,7 +161,6 @@ class RawConfig { interfaces: interfaces ?? this.interfaces, obfuscation: obfuscation ?? this.obfuscation, imports: imports, - className: className, rawMap: rawMap, ); }