@ewb/translate
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -15,3 +15,4 @@ "use strict"; | ||
} | ||
add(translations) { | ||
add(translations = {}) { | ||
this.translations = translations; | ||
if (this.branch instanceof Branch_1.default) { | ||
@@ -18,0 +19,0 @@ this.branch.add(this.word, translations, this.apiID); |
@@ -5,2 +5,3 @@ import Tree, { WordTranslations, TreeOptions } from './Tree'; | ||
import { ISO_639_1 } from './utils/iso_639_1'; | ||
import { TranslationApi } from './TranslationApi'; | ||
declare type NoMatchFn = (translate: Translate, empty: Empty) => void; | ||
@@ -43,2 +44,2 @@ declare type NoTranslationFn = (translate: Translate, empty: Branch) => void; | ||
} | ||
export { Tree, Empty, Branch, Translate, TranslateOptions, WordTranslations, TreeOptions, Translations, BranchObject, Variables, TextOptions, ISO_639_1 }; | ||
export { Tree, Empty, Branch, Translate, TranslateOptions, WordTranslations, TreeOptions, Translations, BranchObject, Variables, TextOptions, ISO_639_1, TranslationApi }; |
@@ -14,3 +14,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Translate = exports.Branch = exports.Empty = exports.Tree = void 0; | ||
const Tree_1 = require("./Tree"); | ||
@@ -23,2 +22,4 @@ exports.Tree = Tree_1.default; | ||
const helpers_1 = require("./utils/helpers"); | ||
const TranslationApi_1 = require("./TranslationApi"); | ||
exports.TranslationApi = TranslationApi_1.TranslationApi; | ||
class Translate { | ||
@@ -25,0 +26,0 @@ constructor({ defaultLocale = 'en', locale = 'en', words = {}, texts = {}, noMatch, noTranslation }) { |
@@ -12,3 +12,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TranslationApi = void 0; | ||
let translateApi; | ||
@@ -42,5 +41,3 @@ class TranslationApi { | ||
const translation = obj[language]; | ||
if (translation[0] && typeof translation[0] === 'object') { | ||
translations[language] = translation[0].value; | ||
} | ||
translations[language] = translation.map(x => x.value).join(','); | ||
} | ||
@@ -58,3 +55,5 @@ } | ||
.join('&'); | ||
const res = yield fetch(`${this.url}/translations/${wordOrId}?${queries}`); | ||
const res = yield fetch(`${this.url}/translations/${wordOrId}?${queries}`, { | ||
credentials: 'omit' | ||
}); | ||
if (res.status > 400) { | ||
@@ -82,3 +81,3 @@ throw new Error(res.statusText); | ||
if (res.status > 400) { | ||
console.error(yield res.json()); | ||
console.error(res); | ||
throw new Error(res.statusText); | ||
@@ -114,7 +113,3 @@ } | ||
return Object.keys(data) | ||
.map(key => { | ||
return (encodeURIComponent(String(key)) + | ||
'=' + | ||
encodeURIComponent(data[key])); | ||
}) | ||
.map(key => `${encodeURIComponent(String(key))}=${encodeURIComponent(data[key])}`) | ||
.join('&'); | ||
@@ -121,0 +116,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.arrayToObject = exports.getFirst = exports.suggestions = exports.getWord = exports.VARIABLE_REGEXP = void 0; | ||
exports.VARIABLE_REGEXP = /{{(.*?)}}/g; | ||
@@ -5,0 +4,0 @@ function getWord(level, word, sentence = false) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.add = void 0; | ||
exports.add = (a, b) => a + b; | ||
//# sourceMappingURL=math.js.map |
{ | ||
"name": "@ewb/translate", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"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", |
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
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
68122
671