-
Notifications
You must be signed in to change notification settings - Fork 483
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
Adding I18n string tracking decorator #36493
Conversation
@@ -8,4 +8,9 @@ | |||
*/ | |||
// locale for applab | |||
|
|||
export default window.locales.applab_locale; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this file doesn't use safeLoadLocale
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably an oversight on my part when I originally implemented that helper. I certainly don't recall intentionally excluding applab
} | ||
|
||
export default function localeWithI18nStringTracker(locale, source) { | ||
if (!experiments.isEnabled(experiments.I18N_TRACKING)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against it but why do we need an experiment here? We're not uploading anything yet, plus this flag needs a deploy to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for protection in case this wrapper does some how screw things up when deployed to the wild. I did try testing on all the level types, but I'm trying to be extra careful since this is a wide impacting change. I'd rather do another deploy to turn on the feature rather than an emergency deploy to turn it off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
@@ -8,4 +8,9 @@ | |||
*/ | |||
// locale for applab | |||
|
|||
export default window.locales.applab_locale; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably an oversight on my part when I originally implemented that helper. I certainly don't recall intentionally excluding applab
apps/src/util/i18nStringTracker.js
Outdated
// Iterates each function in the given locale object and creates a wrapper function. | ||
Object.keys(locale).forEach(function(stringKey, index) { | ||
localeWithTracker[stringKey] = function(d) { | ||
let value = locale[stringKey](d); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
let value = locale[stringKey](d); | |
const value = locale[stringKey](d); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
apps/src/util/i18nStringTracker.js
Outdated
return locale; | ||
} | ||
|
||
let localeWithTracker = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
let localeWithTracker = {}; | |
const localeWithTracker = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
// A map of "string source" -> "list of strings used" | ||
// For example: window.stringUsageSources['maze'] = ['level_1.instruction.header'] | ||
// The data recorded in this will periodically be uploaded. | ||
if (!window.stringUsageSources) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the motivation behind attaching this to the global window
object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted somewhere to buffer them and have evidence that it's intercepting the string usage and logging it.
In a follow-up PR, where I actually use the buffer where the string usage is logged, I will re-evaluate what the best way to implement this buffer is. I will follow-up with you offline to see if you have any recommendations.
35444c8
to
f3f8331
Compare
As a code.org developer, I want to record what I18n strings we are using in our Javascript code.
This PR adds a decorator to our i18n strings (*_locale.js files) which stores the string key and the file it came from to
window.stringUsageSources
. The records stored in this object will periodically be uploaded by a worker thread to our webservers and uploaded to Firehose (the worker thread will be implemented in a future PR).i18nStringTracker.js
which decorates a given *_locale.js object so its usage can be recorded.window.stringUsageSources
Example
window.stringUsageSources
Links
Testing story
window.locales.<locale_file>
towindow.stringUsageSources
Reviewer Checklist: