chore(plugin-i18n): Ported to v3
This commit is contained in:
parent
8f0a69f056
commit
f8c2b61e00
6 changed files with 27 additions and 17 deletions
|
@ -14,7 +14,7 @@ const banner = `/**
|
|||
const options = {
|
||||
banner: { js: banner },
|
||||
bundle: true,
|
||||
entryPoints: ['src/index.js'],
|
||||
entryPoints: ['src/index.mjs'],
|
||||
format: 'esm',
|
||||
outfile: 'dist/index.mjs',
|
||||
external: ["@freesewing"],
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 70 KiB |
|
@ -38,7 +38,7 @@
|
|||
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
||||
"lab": "cd ../../sites/lab && yarn start",
|
||||
"tips": "node ../../scripts/help.mjs",
|
||||
"prettier": "npx prettier --write 'src/*.js' 'tests/*.mjs'",
|
||||
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
|
||||
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
|
||||
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
||||
},
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import pkg from '../package.json'
|
||||
import { name, version } from '../package.json'
|
||||
|
||||
export default {
|
||||
name: pkg.name,
|
||||
version: pkg.version,
|
||||
export const plugin = {
|
||||
name,
|
||||
version,
|
||||
hooks: {
|
||||
preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-i18n', pkg.version),
|
||||
insertText: (locale, text, data) => {
|
||||
if (!data) {
|
||||
console.log(
|
||||
|
@ -19,3 +18,8 @@ export default {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
// More specifically named exports
|
||||
export const i18nPlugin = plugin
|
||||
export const pluginI18n = plugin
|
||||
|
|
@ -1,19 +1,26 @@
|
|||
import chai from 'chai'
|
||||
import freesewing from '@freesewing/core'
|
||||
import plugin from '../dist/index.mjs'
|
||||
import i18n from '../../../packages/i18n/dist/en/index.mjs'
|
||||
import { Pattern } from '@freesewing/core'
|
||||
import { plugin } from '../dist/index.mjs'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
const content = {
|
||||
strings: {
|
||||
en: {
|
||||
testString: 'This is a test string for the i18n plugin'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('I18n Plugin Tests', () => {
|
||||
it('Should translate text on insert', () => {
|
||||
const pattern = new freesewing.Pattern().use(plugin, { strings: { en: i18n.plugin } })
|
||||
const pattern = new Pattern().use(plugin, content)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr(
|
||||
'data-text',
|
||||
'cutTwoStripsToFinishTheArmholes'
|
||||
'testString'
|
||||
)
|
||||
const svg = pattern.draft().render()
|
||||
expect(svg).to.contain('Cut two strips to finish the armholes')
|
||||
expect(svg).to.contain(content.strings.en.testString)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// This file is auto-generated.
|
||||
// Changes you make will be overwritten.
|
||||
import plugin from './dist/index.mjs'
|
||||
// This file is auto-generated | Any changes you make will be overwritten.
|
||||
import { plugin } from './dist/index.mjs'
|
||||
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
||||
|
||||
|
||||
// Run shared tests
|
||||
sharedPluginTests(plugin)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue