Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/expose_loca_strings expose_locale_maps options #30

Merged
merged 13 commits into from Sep 20, 2020

Conversation

defuncart
Copy link
Collaborator

Adds the options for expose_loca_strings and expose_locale_maps. Resolves #27.

expose_loca_strings

flappy_translator:
  expose_loca_strings: true
/// Returns a map of key-locastring for the selected locale
///
/// ```dart
/// {
///   'test': 'Hello world!',
/// }
/// ```
Map<String, String> get locaStrings => _localizedValues;

expose_locale_maps

flappy_translator:
  expose_locale_maps: true
/// Returns a map of loca maps per locale
///
/// ```dart
/// {
///   'en': {'test': 'Hello world!'},
///   'de_CH': {'test': 'Hallo welt!'},
/// }
/// ```
Map<String, Map<String, String>> get localeMaps => _allValues;

@defuncart
Copy link
Collaborator Author

@chang-ran Please let me know if this would solve your issue. This can be tested as follows:

flappy_translator:
   git:
        url: https://github.com/smartnsoft/FlappyTranslator
        ref: feature/options-all-strings-all-locales

@chang-ran
Copy link

I have test this branch and the localeMaps can perfectly solve my problem !

@defuncart
Copy link
Collaborator Author

Updated PR so that locaStrings and localeMaps are copies of original data, otherwise loca strings could be accidentally changed.

/// Returns a map of key-locastring for the current locale
  ///
  /// ```dart
  /// {
  ///   'test': 'Hello world!',
  /// }
  /// ```
  Map<String, String> get locaStrings => Map<String, String>.from(_localizedValues);

  /// Returns a map of loca maps per locale
  ///
  /// ```dart
  /// {
  ///   'en': {'test': 'Hello world!'},
  ///   'de': {'test': 'Hallo welt!'},
  /// }
  /// ```
  Map<String, Map<String, String>> get localeMaps {
    final returnMap = <String, Map<String, String>>{};
    _allValues.forEach(
      (key, value) => returnMap[key] = Map<String, String>.from(value),
    );
    return returnMap;
  }

@defuncart defuncart merged commit 899b215 into master Sep 20, 2020
@defuncart defuncart deleted the feature/options-all-strings-all-locales branch September 20, 2020 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can we change _allValues?
2 participants