-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from zetkin/issue-29-multi-yaml-add-type-part1
Issue 29 multi yaml add type part1
- Loading branch information
Showing
9 changed files
with
110 additions
and
28 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
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
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
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
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
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,35 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
|
||
import { getTranslationsIdText } from './translationObjectUtil'; | ||
|
||
describe('translationObjectUtil', () => { | ||
describe('getTranslationsIdText()', () => { | ||
it('returns empty object for empty obj', () => { | ||
const actual = getTranslationsIdText({}); | ||
expect(actual).toEqual({}); | ||
}); | ||
it('dehydrate obj one property', () => { | ||
const actual = getTranslationsIdText({ | ||
a: { sourceFile: '', text: 'A' }, | ||
}); | ||
expect(actual).toEqual({ a: 'A' }); | ||
}); | ||
it('unflat simple obj one object property', () => { | ||
const actual = getTranslationsIdText({ | ||
'a.b.c': { sourceFile: '', text: 'ABC' }, | ||
}); | ||
expect(actual).toEqual({ 'a.b.c': 'ABC' }); | ||
}); | ||
it('unflat two properties obj', () => { | ||
const actual = getTranslationsIdText({ | ||
'a.b.c': { sourceFile: '', text: 'ABC' }, | ||
'a.b.e': { sourceFile: '', text: 'ABE' }, | ||
}); | ||
const expected = { | ||
'a.b.c': 'ABC', | ||
'a.b.e': 'ABE', | ||
}; | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import { MessageMap } from '@/utils/adapters'; | ||
|
||
/** | ||
* get basic object of message id and text from MessageMap, by remove sourceFile and keep text | ||
* ex: { 'a.b.c': {sourceFile, text} } => { 'a.b.c': 'text' } } } | ||
*/ | ||
export function getTranslationsIdText( | ||
messageMap: MessageMap, | ||
): Record<string, string> { | ||
const result: Record<string, string> = {}; | ||
Object.entries(messageMap).forEach(([id, mt]) => { | ||
result[id] = mt.text; | ||
}); | ||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.
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