Skip to content

Commit

Permalink
docs: update injection and class name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto committed Dec 4, 2023
1 parent 12857e3 commit 0bda1d8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 49 deletions.
76 changes: 39 additions & 37 deletions slang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -405,42 +407,42 @@ targets:

</details>

| 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<String>` | 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<String>` | entries which have cardinals | `[]` |
| `pluralization`/`ordinal` | `List<String>` | entries which have ordinals | `[]` |
| `<context>`/`enum` | `List<String>` | DEPRECATED: context forms [(i)](#-custom-contexts--enums) | no default |
| `<context>`/`paths` | `List<String>` | DEPRECATED: entries using this context | `[]` |
| `<context>`/`default_parameter` | `String` | default parameter name | `context` |
| `<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<String>` | 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<String>` | 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<String>` | entries which have cardinals | `[]` |
| `pluralization`/`ordinal` | `List<String>` | entries which have ordinals | `[]` |
| `<context>`/`enum` | `List<String>` | DEPRECATED: context forms [(i)](#-custom-contexts--enums) | no default |
| `<context>`/`paths` | `List<String>` | DEPRECATED: entries using this context | `[]` |
| `<context>`/`default_parameter` | `String` | default parameter name | `context` |
| `<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<String>` | generate import statements | `[]` |

## Main Features

Expand Down Expand Up @@ -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<StringsEn>((ref) => german); // set it
final translationProvider = StateProvider<Translations>((ref) => german); // set it
// access the current instance
final t = ref.watch(translationProvider);
Expand Down
8 changes: 4 additions & 4 deletions slang/documentation/dependency_injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringsEn>((ref) => german); // set it
final translationProvider = StateProvider<Translations>((ref) => german); // set it
// access the current instance
final t = ref.watch(translationProvider);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion slang/lib/builder/builder/generate_config_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,7 +38,6 @@ class GenerateConfigBuilder {
interface: interfaces,
obfuscation: config.obfuscation,
imports: config.imports,
className: config.className,
);
}
}
2 changes: 1 addition & 1 deletion slang/lib/builder/builder/raw_config_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() ??
Expand Down Expand Up @@ -107,7 +108,6 @@ class RawConfigBuilder {
?.toObfuscationConfig() ??
RawConfig.defaultObfuscationConfig,
imports: map['imports']?.cast<String>() ?? RawConfig.defaultImports,
className: map['class_name'] ?? RawConfig.defaultClassName,
rawMap: map,
);
}
Expand Down
4 changes: 2 additions & 2 deletions slang/lib/builder/model/generate_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +27,6 @@ class GenerateConfig {
final List<Interface> interface; // may include more than in build config
final ObfuscationConfig obfuscation;
final List<String> imports;
final String className;

GenerateConfig({
required this.buildConfig,
Expand All @@ -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,
Expand All @@ -47,6 +48,5 @@ class GenerateConfig {
required this.interface,
required this.obfuscation,
required this.imports,
required this.className,
});
}
8 changes: 4 additions & 4 deletions slang/lib/builder/model/raw_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +39,6 @@ class RawConfig {
static final ObfuscationConfig defaultObfuscationConfig =
ObfuscationConfig.disabled();
static const List<String> defaultImports = <String>[];
static const String defaultClassName = 'Translations';

final FileType fileType;
final I18nLocale baseLocale;
Expand All @@ -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;
Expand All @@ -70,7 +71,6 @@ class RawConfig {
final List<InterfaceConfig> interfaces;
final ObfuscationConfig obfuscation;
final List<String> imports;
final String className;

/// Used by external tools to access the raw config. (e.g. slang_gpt)
final Map<String, dynamic> rawMap;
Expand All @@ -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,
Expand All @@ -105,7 +106,6 @@ class RawConfig {
required this.interfaces,
required this.obfuscation,
required this.imports,
required this.className,
required this.rawMap,
}) : fileType = _determineFileType(inputFilePattern);

Expand Down Expand Up @@ -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,
Expand All @@ -160,7 +161,6 @@ class RawConfig {
interfaces: interfaces ?? this.interfaces,
obfuscation: obfuscation ?? this.obfuscation,
imports: imports,
className: className,
rawMap: rawMap,
);
}
Expand Down

0 comments on commit 0bda1d8

Please sign in to comment.