File tree Expand file tree Collapse file tree 1 file changed +23
-23
lines changed
Expand file tree Collapse file tree 1 file changed +23
-23
lines changed Original file line number Diff line number Diff line change @@ -83,33 +83,33 @@ export function getLanguage(): string {
8383export 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
115115export function useTranslation ( basePath ?: string ) {
You can’t perform that action at this time.
0 commit comments