Skip to content

[FEAT] Loading namespaces with useTranslation and useTranslate hooks. #7195

@indramal

Description

@indramal

Is your feature request related to a problem? Please describe.

Current method we need to add namespaces for each t.

According Refine docs, https://refine.dev/core/docs/i18n/i18n-provider/#translate

const { translate } = useTranslation();
translate("posts.fields.title", { ns: "resources" }, "Title");

But i18next support directly load with useTranslation hook - https://react.i18next.com/latest/usetranslation-hook#loading-namespaces

// load a specific namespace
// the t function will be set to that namespace as default
const { t, i18n } = useTranslation('ns1');
t('key'); // will be looked up from namespace ns1

// load multiple namespaces
// the t function will be set to first namespace as default
const { t, i18n } = useTranslation(['ns1', 'ns2', 'ns3']);
t('key'); // will be looked up from namespace ns1

This method will reduce boilerplate codes.

Describe alternatives you've considered

No response

Additional context

No response

Describe the thing to improve

I believe useTranslation and useTranslate get namespaces input as array or string like i18next package provide. Then directly give to options. Current method can not give namespaces as input.

export const useTranslation = () => {

export const useTranslate = () => {

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions