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

[Sugestion] Use dart extensions allowing get the translated text from String objects #7

Open
hjJunior opened this issue Apr 8, 2020 · 3 comments

Comments

@hjJunior
Copy link

hjJunior commented Apr 8, 2020

I'd like to suggest this feature, which I've made locally on my project, it helped me to access in a less verbose way :)

But there is the problem of compatibility (we need to force the SDK minimum version up to 2.6.0)

Usage

Most basic

'app:label'.t(context)

Passing arguments

    final yourText = 'app:translate-key'.t(
      context,
      variables: {
        'var1': 'value1',
      },
    );

Implementation

extension I18nStringExtension on String {
  String t(
    BuildContext context, {
    Locale locale,
    String tContext,
    int count,
    Map<String, Object> variables,
    I18NextOptions options,
  }) {
    return I18Next.of(context).t(
      this,
      context: tContext,
      count: count,
      locale: locale,
      options: options,
      variables: variables,
    );
  }
}

You u'all agree with the idea, I can open an PR :)

@hjJunior hjJunior changed the title [Sugestion] Use dart extensions allowing get the translated text from String type [Sugestion] Use dart extensions allowing get the translated text from String objects Apr 8, 2020
@williamhjcho
Copy link
Contributor

The problem with using extensions would be bumping the sdk min version to 2.7.0

Would you know a good way of keeping them "semantically" stable?

@hjJunior
Copy link
Author

I'm not too sure about it too, I guess the only way is bumping the min SDK version.
All packages using this feature that I looked for have defined this minimum SDK version...

@williamhjcho
Copy link
Contributor

Hey, @hjJunior would you be willing to add the extension?

Ahmadre pushed a commit to Ahmadre/i18next that referenced this issue Oct 2, 2023
feat: adds escaping variables by default
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

No branches or pull requests

2 participants