-
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.
- Loading branch information
Showing
3 changed files
with
11 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
const getLocale = require('./lib/locale') | ||
const parser = require('./lib/parser') | ||
const getLocale = require('./lib/locale') | ||
|
||
module.exports = class { | ||
constructor(dir, locale) { | ||
this.dir = dir | ||
this.localeData = locale ? getLocale(dir, locale) : {} | ||
this.currentLocale = locale | ||
} | ||
|
||
set locale(locale) { | ||
this.localeData = getLocale(this.dir, locale) | ||
this.currentLocale = locale | ||
} | ||
|
||
get locale() { | ||
return this.currentLocale | ||
} | ||
|
||
parser(type, ...args) { | ||
const localeData = getLocale(this.dir, this.currentLocale) | ||
return parser(type, localeData, ...args) | ||
} | ||
|
||
__(...args) { | ||
return parser('_', this.localeData, ...args) | ||
return this.parser('_', ...args) | ||
} | ||
|
||
_n(...args) { | ||
return parser('n', this.localeData, ...args) | ||
return this.parser('n', ...args) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
const { existsSync, readFileSync } = require('fs') | ||
const { readFileSync } = require('fs') | ||
const { join } = require('path') | ||
const yaml = require('js-yaml') | ||
const logger = require('@acyort/logger')() | ||
|
||
module.exports = (dir, locale) => { | ||
const path = join(dir, `${locale}.yml`) | ||
|
||
if (!existsSync(path)) { | ||
logger.warn(`Cannot load locale \`${locale}\``) | ||
return {} | ||
} | ||
|
||
try { | ||
return yaml.safeLoad(readFileSync(path, 'utf8')) | ||
} catch (e) { | ||
logger.warn(`Cannot load locale \`${locale}\``) | ||
logger.warn(`cannot load locale \`${locale}\``) | ||
return {} | ||
} | ||
} |
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