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

defaultValue support async function #763

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

Conversation

guoyunhe
Copy link
Contributor

@guoyunhe guoyunhe commented Jan 18, 2023

Why am I submitting this PR

With async defaultValue config, users can call Google/Bing Translate API to initialize translations:

import bingTranslateApi from 'bing-translate-api';
import { languageCodes } from './src/config/i18n';

export default {
  locales: languageCodes,
  input: ['src/**/*.{js,jsx,ts,tsx}'],
  output: 'public/locales/$LOCALE/$NAMESPACE.json',
  indentation: 2,
  keySeparator: false,
  namespaceSeparator: false,
  defaultValue: async (locale: string, namespace: string, key: string) => {
    if (locale === 'en') {
      return key;
    } else {
      try {
        const result = await bingTranslateApi.translate(key, 'en', locale);
        return result.translation;
      } catch (e) {
        console.log(e);
        return '';
      }
    }
  },
};

Does it fix an existing ticket?

Yes/No #000

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • tests are included and pass: yarn test (see details here)
  • documentation is changed or added

@codecov-commenter
Copy link

Codecov Report

Base: 94.08% // Head: 94.08% // No change to project coverage 👍

Coverage data is based on head (2353dae) compared to base (432cb66).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #763   +/-   ##
=======================================
  Coverage   94.08%   94.08%           
=======================================
  Files          11       11           
  Lines        1742     1742           
=======================================
  Hits         1639     1639           
  Misses        103      103           
Impacted Files Coverage Δ
src/helpers.js 92.17% <100.00%> (ø)
src/transform.js 88.25% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@karellm karellm force-pushed the master branch 2 times, most recently from d72e758 to 10f3d69 Compare May 8, 2023 03:17
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.

None yet

2 participants