-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i18n: Translate first blog post but keep RSS feed working
- Loading branch information
1 parent
7e0a012
commit 253b15c
Showing
7 changed files
with
131 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import defaultTranslations from "@/i18n/translations.en.json"; | ||
|
||
export type TranslationObject = { | ||
[key: string]: string | TranslationObject; | ||
}; | ||
|
||
export const getNestedTranslation = ( | ||
obj: TranslationObject, | ||
key: string, | ||
): string | undefined => { | ||
let acc: TranslationObject | string | undefined = obj; | ||
for (let i = 0; i < key.split(".").length; i++) { | ||
const part = key.split(".")[i]; | ||
if (acc && typeof acc !== "string" && acc[part] !== undefined) { | ||
acc = acc[part]; | ||
} else { | ||
acc = undefined; // If a part is not found, stop and return undefined | ||
break; | ||
} | ||
} | ||
return typeof acc === "string" ? acc : undefined; | ||
}; | ||
|
||
export function getBaseTranslation(translationKey: string): string { | ||
return ( | ||
getNestedTranslation(defaultTranslations, translationKey) || translationKey | ||
); | ||
} |
This file contains 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