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

Allow overriding label for input inside TranslatableInputs #6415

Merged
merged 3 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ra-core/src/i18n/TranslatableContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export interface TranslatableContextValue {
}

export type GetTranslatableSource = (field: string, locale?: string) => string;
export type GetTranslatableLabel = (field: string) => string;
export type GetTranslatableLabel = (field: string, label?: string) => string;
export type SelectTranslatableLocale = (locale: string) => void;
6 changes: 3 additions & 3 deletions packages/ra-core/src/i18n/useTranslatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import useTranslate from './useTranslate';
* An object with following properties and methods:
* - selectedLocale: The locale of the currently selected locale
* - locales: An array of the supported locales
* - getLabelInput: A function which returns the translated label for the given field
* - getLabel: A function which returns the translated label for the given field
* - getSource: A function which returns the source for the given field
* - selectLocale: A function which set the selected locale
*/
Expand All @@ -33,12 +33,12 @@ export const useTranslatable = (
() => ({
getSource: (source: string, locale: string = selectedLocale) =>
`${source}.${locale}`,
getLabel: (source: string) => {
getLabel: (source: string, label?: string) => {
return translate(
...getFieldLabelTranslationArgs({
source,
resource,
label: undefined,
label,
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export const TranslatableInputsTabContent = (
basePath={basePath}
input={cloneElement(child, {
...child.props,
label: getLabel(child.props.source),
label: getLabel(
child.props.source,
child.props.label
),
source: getSource(child.props.source, locale),
})}
record={record}
Expand Down