@ewb/translate
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -106,6 +106,6 @@ "use strict"; | ||
const split = word.split(' ')[this.level + 1]; | ||
return split ? split.toLowerCase() : ''; | ||
return split ? split.toLocaleLowerCase() : ''; | ||
} | ||
else { | ||
return word[this.level + 1] ? word[this.level + 1].toLowerCase() : ''; | ||
return word[this.level + 1] || ''; | ||
} | ||
@@ -125,2 +125,8 @@ } | ||
nw = newWord.split(' ')[this.level]; | ||
if (w) { | ||
w = w.toLocaleLowerCase(); | ||
} | ||
if (nw) { | ||
nw = nw.toLocaleLowerCase(); | ||
} | ||
} | ||
@@ -131,6 +137,8 @@ else { | ||
} | ||
return Boolean(w && nw && w.toLowerCase() !== nw.toLowerCase()); | ||
return Boolean(w && nw && w !== nw); | ||
} | ||
matchWord(newWord) { | ||
return this.word.toLowerCase() === newWord.toLowerCase(); | ||
return this.sentence | ||
? this.word.toLocaleLowerCase() === newWord.toLocaleLowerCase() | ||
: this.word === newWord; | ||
} | ||
@@ -137,0 +145,0 @@ } |
@@ -28,3 +28,3 @@ import Tree, { WordTranslations, TreeOptions } from './Tree'; | ||
private readonly noTranslation; | ||
constructor({ defaultLocale, locale, words, texts, noMatch, noTranslation }?: TranslateOptions); | ||
constructor({ defaultLocale, locale, words, texts, noMatch, noTranslation }?: TranslateOptions, overrideNew?: boolean); | ||
w(word: string, locale?: string): string; | ||
@@ -31,0 +31,0 @@ word(word: string, locale?: string): string; |
@@ -26,7 +26,7 @@ "use strict"; | ||
class Translate { | ||
constructor({ defaultLocale = 'en', locale = 'en', words = {}, texts = {}, noMatch, noTranslation } = {}) { | ||
constructor({ defaultLocale = 'en', locale = 'en', words = {}, texts = {}, noMatch, noTranslation } = {}, overrideNew) { | ||
this.defaultLocale = ''; | ||
this.locale = ''; | ||
this.tree = new Tree_1.default({}); | ||
if (translate) { | ||
if (!overrideNew && translate) { | ||
return translate; | ||
@@ -33,0 +33,0 @@ } |
@@ -23,5 +23,5 @@ "use strict"; | ||
if (isText) { | ||
return word.split(' ')[0].toLowerCase(); | ||
return word.split(' ')[0].toLocaleLowerCase(); | ||
} | ||
return word[0].toLowerCase(); | ||
return word[0]; | ||
} | ||
@@ -28,0 +28,0 @@ exports.getFirst = getFirst; |
{ | ||
"name": "@ewb/translate", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Translate as you create your app. Saves the words and text in a tree structure for fast and easy lookup.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -157,5 +157,5 @@ import Empty from './Empty'; | ||
const split = word.split(' ')[this.level + 1]; | ||
return split ? split.toLowerCase() : ''; | ||
return split ? split.toLocaleLowerCase() : ''; | ||
} else { | ||
return word[this.level + 1] ? word[this.level + 1].toLowerCase() : ''; | ||
return word[this.level + 1] || ''; | ||
} | ||
@@ -179,2 +179,8 @@ } | ||
nw = newWord.split(' ')[this.level]; | ||
if (w) { | ||
w = w.toLocaleLowerCase(); | ||
} | ||
if (nw) { | ||
nw = nw.toLocaleLowerCase(); | ||
} | ||
} else { | ||
@@ -185,8 +191,10 @@ w = this.word[this.level]; | ||
return Boolean(w && nw && w.toLowerCase() !== nw.toLowerCase()); | ||
return Boolean(w && nw && w !== nw); | ||
} | ||
private matchWord(newWord: string) { | ||
return this.word.toLowerCase() === newWord.toLowerCase(); | ||
return this.sentence | ||
? this.word.toLocaleLowerCase() === newWord.toLocaleLowerCase() | ||
: this.word === newWord; | ||
} | ||
} |
@@ -38,11 +38,14 @@ import Tree, { WordTranslations, TreeOptions } from './Tree'; | ||
constructor({ | ||
defaultLocale = 'en', | ||
locale = 'en', | ||
words = {}, | ||
texts = {}, | ||
noMatch, | ||
noTranslation | ||
}: TranslateOptions = {}) { | ||
if (translate) { | ||
constructor( | ||
{ | ||
defaultLocale = 'en', | ||
locale = 'en', | ||
words = {}, | ||
texts = {}, | ||
noMatch, | ||
noTranslation | ||
}: TranslateOptions = {}, | ||
overrideNew?: boolean | ||
) { | ||
if (!overrideNew && translate) { | ||
return translate; | ||
@@ -49,0 +52,0 @@ } |
@@ -23,5 +23,5 @@ import Branch from '../Branch'; | ||
if (isText) { | ||
return word.split(' ')[0].toLowerCase(); | ||
return word.split(' ')[0].toLocaleLowerCase(); | ||
} | ||
return word[0].toLowerCase(); | ||
return word[0]; | ||
} | ||
@@ -28,0 +28,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
177065
1605