-
Notifications
You must be signed in to change notification settings - Fork 16
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 all 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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({ | ||
|
|
@@ -319,6 +329,11 @@ export async function getTranslations(id?: string): Promise< | |
| }) | ||
| // (3.b) Inject the translation into the translations object | ||
| .then((result) => { | ||
| console.log('inject entry'); | ||
| console.log('result', result); | ||
| console.log('dictionaryTranslations', dictionaryTranslations); | ||
| console.log('id', id); | ||
| console.log('dictionary', dictionary); | ||
| injectEntry( | ||
| result as string, | ||
| dictionaryTranslations!, | ||
|
|
||
| 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)) { | ||||||
|
|
||||||
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.