-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Improve translations - flatten translation objects #25846
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
Merged
mountiny
merged 19 commits into
Expensify:main
from
BeeMargarida:feat/25466-flatten_translation_objects
Sep 13, 2023
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e3b5852
test: unit test for translation flatten object function
BeeMargarida 82919b7
feat: flatten object function to flatten translation
BeeMargarida 463daff
feat: remove lodashGet from translate
BeeMargarida 62d4e91
feat: migrate use of languages translate to new solution
BeeMargarida 370d679
feat: migrate use of pronouns translate to new solution
BeeMargarida 9f84e42
feat: migrate use of countries and states translate to new solution
BeeMargarida 6548241
style: prettier
BeeMargarida f38a0bf
fix: small error
BeeMargarida 2fef893
refactor: move unit test to translate unit suite
BeeMargarida 9d8b224
fix: remove unused usage
BeeMargarida ad78499
feat: rename const
BeeMargarida 0088b39
feat: switch us states const to an array of ISOs
BeeMargarida e86a966
Merge branch 'main' into feat/25466-flatten_translation_objects
BeeMargarida c6bf5df
Merge branch 'main' into feat/25466-flatten_translation_objects
BeeMargarida 8db1cda
Merge branch 'main' into feat/25466-flatten_translation_objects
BeeMargarida 1ac2cde
Merge branch 'main' into feat/25466-flatten_translation_objects
BeeMargarida be487e7
feat: improve translation types
BeeMargarida 2931a45
refactor: rename generics
BeeMargarida 8f8420a
style: prettier
BeeMargarida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,9 +1,51 @@ | ||
import _ from 'underscore'; | ||
import en from './en'; | ||
import es from './es'; | ||
import esES from './es-ES'; | ||
|
||
/** | ||
* Converts an object to it's flattened version. | ||
* | ||
* Ex: | ||
* Input: { common: { yes: "Yes", no: "No" }} | ||
* Output: { "common.yes": "Yes", "common.no": "No" } | ||
* | ||
* @param {Object} obj | ||
* @returns {Object} | ||
*/ | ||
// Necessary to export so that it is accessible to the unit tests | ||
// eslint-disable-next-line rulesdir/no-inline-named-export | ||
export function flattenObject(obj) { | ||
const result = {}; | ||
|
||
const recursive = (data, key) => { | ||
// If the data is a function or not a object (eg. a string), it's | ||
// the value of the key being built and no need for more recursion | ||
if (_.isFunction(data) || _.isArray(data) || !_.isObject(data)) { | ||
result[key] = data; | ||
} else { | ||
let isEmpty = true; | ||
|
||
// Recursive call to the keys and connect to the respective data | ||
_.keys(data).forEach((k) => { | ||
isEmpty = false; | ||
recursive(data[k], key ? `${key}.${k}` : k); | ||
}); | ||
|
||
// Check for when the object is empty but a key exists, so that | ||
// it defaults to an empty object | ||
if (isEmpty && key) { | ||
result[key] = {}; | ||
} | ||
} | ||
}; | ||
|
||
recursive(obj, ''); | ||
return result; | ||
} | ||
|
||
export default { | ||
en, | ||
es, | ||
en: flattenObject(en), | ||
es: flattenObject(es), | ||
'es-ES': esES, | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.