-
Notifications
You must be signed in to change notification settings - Fork 221
Have ExtractedLocation contain null for locales that are not available (instead of undefined) #494
Conversation
bc793e7
to
2a6c4ef
Compare
packages/react-i18n/src/manager.ts
Outdated
@@ -32,15 +32,15 @@ export default class Manager { | |||
initialTranslations: ExtractedTranslations = {}, | |||
) { | |||
for (const [id, translation] of Object.entries(initialTranslations)) { | |||
this.translations.set(id, translation); | |||
this.translations.set(id, translation || undefined); |
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.
Is this really needed?
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.
Yes, this.translations
is TranslationDictonary | undefined
so null
is not a valid value.
Do you think using
this.translations.set(id, translation === null ? undefined : translation);
instead be more readable?
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.
Oh right I missed that initialTranslations
was an ExtractedTranslations
. || undefined
is fine with me 👍
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 think I would rather change this so that this.translations
has the same "no translation found" type as we give when you serialize it (null
)
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.
The code looks good to me, thanks for this change and the test! 👍
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.
Just one change I think would make things a bit simpler, then LGTM 👍
packages/react-i18n/src/manager.ts
Outdated
@@ -32,15 +32,15 @@ export default class Manager { | |||
initialTranslations: ExtractedTranslations = {}, | |||
) { | |||
for (const [id, translation] of Object.entries(initialTranslations)) { | |||
this.translations.set(id, translation); | |||
this.translations.set(id, translation || undefined); |
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 think I would rather change this so that this.translations
has the same "no translation found" type as we give when you serialize it (null
)
Hey @lemonmade, as I mentioned here:
I did do it that way originally, and it makes the code much more complicated (need to add a lot of |
I don't think any public API needs to change, just how we store them internally. You might have to update where we store them to do |
337cb0a
to
e330349
Compare
This will allow us to serialize the data and keep the information as our serializer removes undefined properties.
e330349
to
bbb9d04
Compare
This will allow use to serialize and keep the information as our serializer removed undefined properties.
It will remove the necessity of a hack around it on web#10270
I decided to change only the
ExtractedTranslations
interface as it will minimise the impact on other systems, makes for a much simpler implementation (asundefined
is the return value in case of failure of a lot of methods likeMap.get
), and its the only place we neednull
.