Skip to content

Commit

Permalink
Merge pull request jdorn#710 from tohosaku/fix_lang
Browse files Browse the repository at this point in the history
Fixed a bug that language customization did not reflect.
  • Loading branch information
schmunk42 authored Apr 16, 2020
2 parents 690bf7c + 04a5806 commit e0d2e8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ function upload (type, file, cbs) {

/* String translate function */
function translate (key, variables) {
const lang = languages[language]
if (!lang) throw new Error(`Unknown language ${language}`)
const lang = defaults.languages[defaults.language]
if (!lang) throw new Error(`Unknown language ${defaults.language}`)

let string = lang[key] || languages[default_language][key]
let string = lang[key] || defaults.languages[default_language][key]

if (typeof string === 'undefined') throw new Error(`Unknown translate string ${key}`)

Expand Down
54 changes: 35 additions & 19 deletions tests/unit/defaults.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
/*
Stub test file
TODO: Write unit tests for all interfaces
*/
import { defaults } from '../../src/defaults'

import { defaults } from '../../src/defaults';
describe('defaults', () => {
it('should be an object', () => {
expect(typeof defaults).toBe('object')
})

it('should have standard properties defined', () => {
expect(typeof (defaults.themes)).toBe('object')
expect(typeof (defaults.templates)).toBe('object')
expect(typeof (defaults.iconlibs)).toBe('object')
expect(typeof (defaults.editors)).toBe('object')
expect(typeof (defaults.languages)).toBe('object')
expect(Array.isArray(defaults.resolvers)).toBe(true)
expect(Array.isArray(defaults.custom_validators)).toBe(true)
})
})

describe("defaults", function() {
it("should be an object", function(){
expect(typeof defaults).toBe("object");
});
it("should have standard properties defined", function(){
expect(typeof(defaults.themes)).toBe("object");
expect(typeof(defaults.templates)).toBe("object");
expect(typeof(defaults.iconlibs)).toBe("object");
expect(typeof(defaults.editors)).toBe("object");
expect(typeof(defaults.languages)).toBe("object");
expect(Array.isArray(defaults.resolvers)).toBe(true);
expect(Array.isArray(defaults.custom_validators)).toBe(true);
});
});
describe('languages test', () => {
beforeEach(() => {
defaults.languages.es = {
error_notset: 'propiedad debe existir'
}
defaults.language = 'es'
})

it('should translate other language', () => {
expect(defaults.translate('error_notset')).toBe('propiedad debe existir')
})

it('should return default message. if no translation', () => {
expect(defaults.translate('error_notempty')).toBe('Value required')
})

it('throw error to unknown translate string', () => {
expect(() => defaults.translate('unknown_message')).toThrow()
})
})

0 comments on commit e0d2e8e

Please sign in to comment.