-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(translation): use translation adapters #1
- Loading branch information
1 parent
ee91a13
commit 830eaa5
Showing
8 changed files
with
64 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TranslationDriverMap } from './types' | ||
|
||
import * as google from './google' | ||
import * as none from './none' | ||
|
||
const drivers: TranslationDriverMap = { google, none } | ||
const chosenDriver = process.env.VUE_APP_TRANSLATION_DRIVER || 'none' | ||
const driver = drivers[chosenDriver] | ||
|
||
if (!driver) { | ||
throw new Error(`Invalid translation driver "${chosenDriver}"`) | ||
} | ||
|
||
const translate = driver.translate | ||
|
||
export { translate } |
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,13 @@ | ||
import { TranslateFunc } from './types' | ||
|
||
const translate: TranslateFunc = async ( | ||
targetLanguage, | ||
sourceText, | ||
sourceLanguage, | ||
) => { | ||
return Promise.resolve().then(() => { | ||
return sourceText | ||
}) | ||
} | ||
|
||
export { translate } |
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,17 @@ | ||
import { LanguageCode } from '@/types' | ||
|
||
export interface TranslateFunc { | ||
( | ||
targetLanguage: LanguageCode, | ||
sourceText: string, | ||
sourceLanguage: LanguageCode, | ||
): Promise<string> | ||
} | ||
|
||
export interface TranslationDriver { | ||
translate: TranslateFunc | ||
} | ||
|
||
export interface TranslationDriverMap { | ||
[key: string]: TranslationDriver | ||
} |
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