fix: 🐛 regression of flat keys separated by dot

This commit is contained in:
Christian Kaisermann 2020-11-08 19:09:45 -03:00
parent f6c826497d
commit d87caef060
2 changed files with 8 additions and 2 deletions

View File

@ -27,6 +27,12 @@ export function getMessageFromDictionary(locale: string, id: string) {
const localeDictionary = getLocaleDictionary(locale); const localeDictionary = getLocaleDictionary(locale);
// flat ids
if (id in localeDictionary) {
return localeDictionary[id];
}
// deep ids
const match = dlv(localeDictionary, id); const match = dlv(localeDictionary, id);
return match; return match;

View File

@ -99,9 +99,9 @@ describe('getting messages', () => {
it('accepts english in dictionary keys', () => { it('accepts english in dictionary keys', () => {
addMessages('pt', { addMessages('pt', {
'Hey man, how are you today?': 'E ai cara, como você vai hoje?', 'Hey man. How are you today?': 'E ai cara, como você vai hoje?',
}); });
expect(getMessageFromDictionary('pt', 'Hey man, how are you today?')).toBe( expect(getMessageFromDictionary('pt', 'Hey man. How are you today?')).toBe(
'E ai cara, como você vai hoje?', 'E ai cara, como você vai hoje?',
); );
}); });