-
Notifications
You must be signed in to change notification settings - Fork 24
E/null dict #675
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
base: main
Are you sure you want to change the base?
E/null dict #675
Changes from 4 commits
4832fe8
02e184c
c08de57
2d18d79
f031181
abd93c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| 'gt-react': patch | ||
| 'gt-next': patch | ||
| --- | ||
|
|
||
| fix: return type for t.obj |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,6 +192,12 @@ export async function getTranslations(id?: string): Promise< | |
| return renderContent(entry, [defaultLocale]); | ||
| } | ||
|
|
||
| // Don't translate non-string entries | ||
| if (typeof entry !== 'string') { | ||
| injectEntry(entry, dictionaryTranslations!, id, dictionary); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: This assumes |
||
| return renderContent(entry, [defaultLocale]); | ||
| } | ||
|
|
||
| try { | ||
| // Translate on demand | ||
| I18NConfig.translateIcu({ | ||
|
|
@@ -306,6 +312,10 @@ export async function getTranslations(id?: string): Promise< | |
| for (const untranslatedEntry of untranslatedEntries) { | ||
| const { source, metadata } = untranslatedEntry; | ||
| const id = metadata?.$id; | ||
| if (typeof source !== 'string') { | ||
| injectEntry(source, dictionaryTranslations!, id, dictionary); | ||
| continue; | ||
| } | ||
|
|
||
| // (3.a) Translate | ||
| I18NConfig.translateIcu({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,12 @@ import { get } from './indexDict'; | |
| export function isValidDictionaryEntry( | ||
| value: unknown | ||
| ): value is DictionaryEntry { | ||
| if (typeof value === 'string') { | ||
| if (typeof value !== 'object' || value === null) { | ||
| return true; | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| if (typeof value?.[0] !== 'string') { | ||
| if (typeof value?.[0] === 'object' && value?.[0] !== null) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Array Validation Fails for Non-String PrimitivesThe array validation logic in Additional Locations (1) |
||
| return false; | ||
|
Comment on lines
+12
to
13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The validation logic has been inverted - now rejects objects (except null) instead of accepting only strings. This creates inconsistency with |
||
| } | ||
| const provisionalMetadata = value?.[1]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { Dictionary, DictionaryEntry } from '../types/types'; | |||||
| * @param id - id of the value to get | ||||||
| */ | ||||||
| export function get(dictionary: Dictionary, id: string | number) { | ||||||
| if (dictionary == null) { | ||||||
| if (dictionary === undefined) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: This change allows null dictionaries to pass through, but accessing properties on null (line 12:
Suggested change
|
||||||
| throw new Error('Cannot index into an undefined dictionary'); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Error message should be updated to reflect that only undefined dictionaries are rejected, or the function should handle null dictionaries explicitly. |
||||||
| } | ||||||
| if (Array.isArray(dictionary)) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,8 @@ export function isDictionaryEntry( | |
| return false; | ||
| } | ||
|
|
||
| // Check if it's a string (Entry) | ||
| if (typeof value === 'string') { | ||
| // Check if it's an entry | ||
| if (value === null || typeof value !== 'object') { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Dictionary Validation Fails for Non-Object PrimitivesThe validation logic in Additional Locations (2) |
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -25,7 +25,7 @@ export function isDictionaryEntry( | |
| } | ||
|
|
||
| // First element must be a string (Entry) | ||
| if (typeof value[0] !== 'string') { | ||
| if (typeof value[0] === 'object' && value[0] !== null) { | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,9 +79,8 @@ export default function useCreateInternalUseTranslationsFunction( | |
| isValidDictionaryEntry(dictionaryTranslation) | ||
| ) { | ||
| const { entry } = getEntryAndMetadata(dictionaryTranslation); | ||
| return renderMessage(entry, [locale, defaultLocale]); | ||
| return renderMessage(entry || '', [locale, defaultLocale]); | ||
| } | ||
|
|
||
| // ----- CHECK TRANSLATIONS ----- // | ||
|
|
||
| let translationEntry = translations?.[id]; | ||
|
|
@@ -118,6 +117,11 @@ export default function useCreateInternalUseTranslationsFunction( | |
| // ----- TRANSLATE ON DEMAND ----- // | ||
| // development only | ||
|
|
||
| // Don't translate non-string entries | ||
| if (typeof entry !== 'string') { | ||
| return renderMessage(entry, [defaultLocale]); | ||
| } | ||
|
Comment on lines
+121
to
+123
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: This type check is redundant since line 59 already handles non-string entries. Consider removing or add a comment explaining why this additional check is necessary. |
||
|
|
||
| // Translate Content | ||
| registerIcuForTranslation({ | ||
| source: entry, | ||
|
|
||
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.
Bug: Translation Merge Code Commented Out
The dictionary merge operation was commented out, disabling the merging of dictionary translations with the base dictionary. This prevents translations from being applied properly and appears to be accidentally committed debugging code.