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

📝 [Update] Use dots when flattening JSON to a single level and separating keys in generate locales #254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

knottx
Copy link
Contributor

@knottx knottx commented Apr 24, 2024

  1. Use dots when flattening JSON to a single level and separating keys in generate locales
  2. Support JSON key contain dots

This format makes it easier to represent nested structures in a flat key-value pair format.

For example

input:
en_US.json

{
  "buttons": {
    "login": "Login",
    "sign_in": "Sign-in",
    "logout": "Logout",
    "sign_in_fb": "Sign-in with Facebook",
    "sign_in_google": "Sign-in with Google",
    "sign_in_apple": "Sign-in with Apple"
  }
}

output:

abstract class AppTranslation {

  static Map<String, Map<String, String>> translations = {
    'en_US' : Locales.en_US,
  };

}
abstract class LocaleKeys {
  static const buttons_login = 'buttons.login';
  static const buttons_sign_in = 'buttons.sign_in';
  static const buttons_logout = 'buttons.logout';
  static const buttons_sign_in_fb = 'buttons.sign_in_fb';
  static const buttons_sign_in_google = 'buttons.sign_in_google';
  static const buttons_sign_in_apple = 'buttons.sign_in_apple';
}

abstract class Locales {
  static const en_US = {
   'buttons.login': 'Login',
   'buttons.sign_in': 'Sign-in',
   'buttons.logout': 'Logout',
   'buttons.sign_in_fb': 'Sign-in with Facebook',
   'buttons.sign_in_google': 'Sign-in with Google',
   'buttons.sign_in_apple': 'Sign-in with Apple',
  };
}

@knottx
Copy link
Contributor Author

knottx commented Apr 25, 2024

@jonataslaw @CpdnCristiano hope you are both well.

@knottx knottx changed the title Use dots when flattening JSON to a single level and separating keys in generate locales [Update] Use dots when flattening JSON to a single level and separating keys in generate locales Apr 25, 2024
@knottx knottx changed the title [Update] Use dots when flattening JSON to a single level and separating keys in generate locales 📝 [Update] Use dots when flattening JSON to a single level and separating keys in generate locales Apr 25, 2024
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.

1 participant