-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: add fallback texts to placeholder text (#690)
* create function to provide fallback texts for placeholder texts * display object value * add fallback text translator to pivot items
- Loading branch information
Showing
2 changed files
with
36 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { geLocale } from '../../appLocale'; | ||
import messages from '../../messages'; | ||
|
||
export function translateMessage(messageId: string): string { | ||
const translatedMessage = getTranslation(messageId, geLocale); | ||
if (translatedMessage) { | ||
return translatedMessage; | ||
} | ||
return getTranslation(messageId, 'en-US') || messageId; | ||
} | ||
|
||
function getTranslation(messageId: string, locale: string) { | ||
const localeMessages: object = (messages as { [key: string]: object })[locale]; | ||
if (localeMessages) { | ||
const key: any = Object.keys(localeMessages).find(k => k === messageId); | ||
const message = (localeMessages as { [key: string]: object })[key]; | ||
if (message) { | ||
return message.toString(); | ||
} | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters