Skip to content

Commit 245e77d

Browse files
authored
Merge pull request #7 from JWebCoder/develop
Develop
2 parents f1b4da0 + fbe20c1 commit 245e77d

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/index.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,33 @@ export function getLanguage(): string {
8383
export function t(path: string, args?: {[key: string]: string}): string {
8484
const translationKeys: string[] = path.split('.')
8585
let translation: string = ''
86-
let translationObj: ITranslation = translations[language]
87-
88-
translationKeys.forEach(
89-
(key: string) => {
90-
const temp: string | ITranslation = translationObj[key]
91-
if (typeof translationObj[key] === 'object') {
92-
translationObj = translationObj[key] as ITranslation
86+
if (translations[language]) {
87+
let translationObj: ITranslation = translations[language]
88+
89+
translationKeys.forEach(
90+
(key: string) => {
91+
const temp: string | ITranslation = translationObj[key]
92+
if (typeof translationObj[key] === 'object') {
93+
translationObj = translationObj[key] as ITranslation
94+
}
95+
if (typeof temp === 'string') {
96+
translation = temp
97+
}
9398
}
94-
if (typeof temp === 'string') {
95-
translation = temp
99+
)
100+
101+
if (translation) {
102+
if (args) {
103+
Object.keys(args).forEach(
104+
(key) => {
105+
translation = translation.replace(`{${key}}`, args ? args[key] : '')
106+
}
107+
)
96108
}
109+
return translation
97110
}
98-
)
99-
100-
if (translation) {
101-
if (args) {
102-
Object.keys(args).forEach(
103-
(key) => {
104-
translation = translation.replace(`{${key}}`, args ? args[key] : '')
105-
}
106-
)
107-
}
108-
} else {
109-
return path
110111
}
111-
112-
return translation
112+
return path
113113
}
114114

115115
export function useTranslation(basePath?: string) {

0 commit comments

Comments
 (0)