Skip to content

Commit

Permalink
🐛 Fix Google service not supporting zh-CN and zh-TW
Browse files Browse the repository at this point in the history
  • Loading branch information
leolabs committed Jul 18, 2021
1 parent 8b34852 commit 156cc1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import { diff } from 'deep-object-diff';
import ncp from 'ncp';

import { serviceMap } from './services';
import { serviceMap, TranslationService } from './services';
import {
loadTranslations,
getAvailableLanguages,
Expand Down Expand Up @@ -396,7 +396,7 @@ translate(
});

function createTranslator(
translationService: typeof serviceMap[any],
translationService: TranslationService,
service: keyof typeof serviceMap,
sourceLang: string,
targetLang: string,
Expand Down
4 changes: 2 additions & 2 deletions src/services/google-translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TranslationService, TString } from '.';
// Contains replacements for language codes
const codeMap = {
'zh-tw': 'zh-TW',
'zh-cn': 'zh-CN',
};

export class GoogleTranslate implements TranslationService {
Expand Down Expand Up @@ -50,12 +51,11 @@ export class GoogleTranslate implements TranslationService {
}

supportsLanguage(language: string) {
return this.supportedLanguages.includes(language);
return this.supportedLanguages.includes(language.toLowerCase());
}

cleanLanguageCode(languageCode: string) {
const lowerCaseCode = languageCode.toLowerCase();
console.log('Lower case:', languageCode);

if (codeMap[lowerCaseCode]) {
return codeMap[lowerCaseCode];
Expand Down

0 comments on commit 156cc1d

Please sign in to comment.