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: key prefix option #1644

Merged
merged 6 commits into from Sep 1, 2021

Conversation

mdjastrzebski
Copy link
Contributor

Adds optional keyPrefix parameter to getFixedT function in order to allows for improved developer experience when querying deeply nested keys with common prefix.

i18next.addResource('fr', 'translation', 'very.deeply.nested.key', 'ici!');
const t = i18next.getFixedT('fr', null, 'very.deeply.nested');
const test = t('key'); // "ici!"

Original GH issue (from react-i18next): i18next/react-i18next#1359

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included

Checklist (for documentation change)

  • only relevant documentation part is changed (make a diff before you submit the PR)
  • motivation/reason is provided

@mdjastrzebski
Copy link
Contributor Author

I would like to also update the docs, I'm not sure how to do it, as I haven't found docs sources in this repo.

index.d.ts Outdated
ns?: string | readonly string[],
keyPrefix?: string,
): TFunction;
getFixedT(lng: null, ns: string | readonly string[], keyPrefix?: string): TFunction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably an additional signature with second argument null is also needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated second signature to allow null value for ns argument. This should have the same effect as creating third signature getFixedT(lng: null, ns: null, keyPrefix?: string): TFunction;. @adrai wdyt?

@coveralls
Copy link

coveralls commented Sep 1, 2021

Coverage Status

Coverage increased (+0.006%) to 93.234% when pulling 56b3b17 on mdjastrzebski:feature/key-prefix-option into e8566a0 on i18next:master.

@adrai
Copy link
Member

adrai commented Sep 1, 2021

@adrai
Copy link
Member

adrai commented Sep 1, 2021

beside the typescript signature, it lgtm

@adrai adrai merged commit e3e9381 into i18next:master Sep 1, 2021
@adrai
Copy link
Member

adrai commented Sep 1, 2021

Thank you. v20.6.0 has just been released.

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

3 participants