1
0
Fork 0

chore(plugin-i18n): Ported to v3

This commit is contained in:
Joost De Cock 2022-08-28 12:44:22 +02:00
parent 8f0a69f056
commit f8c2b61e00
6 changed files with 27 additions and 17 deletions

View file

@ -14,7 +14,7 @@ const banner = `/**
const options = { const options = {
banner: { js: banner }, banner: { js: banner },
bundle: true, bundle: true,
entryPoints: ['src/index.js'], entryPoints: ['src/index.mjs'],
format: 'esm', format: 'esm',
outfile: 'dist/index.mjs', outfile: 'dist/index.mjs',
external: ["@freesewing"], external: ["@freesewing"],

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

View file

@ -38,7 +38,7 @@
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs", "vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
"lab": "cd ../../sites/lab && yarn start", "lab": "cd ../../sites/lab && yarn start",
"tips": "node ../../scripts/help.mjs", "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", "testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
"cibuild_step1": "node --experimental-json-modules build.mjs" "cibuild_step1": "node --experimental-json-modules build.mjs"
}, },

View file

@ -1,10 +1,9 @@
import pkg from '../package.json' import { name, version } from '../package.json'
export default { export const plugin = {
name: pkg.name, name,
version: pkg.version, version,
hooks: { hooks: {
preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-i18n', pkg.version),
insertText: (locale, text, data) => { insertText: (locale, text, data) => {
if (!data) { if (!data) {
console.log( console.log(
@ -19,3 +18,8 @@ export default {
}, },
}, },
} }
// More specifically named exports
export const i18nPlugin = plugin
export const pluginI18n = plugin

View file

@ -1,19 +1,26 @@
import chai from 'chai' import chai from 'chai'
import freesewing from '@freesewing/core' import { Pattern } from '@freesewing/core'
import plugin from '../dist/index.mjs' import { plugin } from '../dist/index.mjs'
import i18n from '../../../packages/i18n/dist/en/index.mjs'
const expect = chai.expect const expect = chai.expect
const content = {
strings: {
en: {
testString: 'This is a test string for the i18n plugin'
}
}
}
describe('I18n Plugin Tests', () => { describe('I18n Plugin Tests', () => {
it('Should translate text on insert', () => { 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 = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr( pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr(
'data-text', 'data-text',
'cutTwoStripsToFinishTheArmholes' 'testString'
) )
const svg = pattern.draft().render() const svg = pattern.draft().render()
expect(svg).to.contain('Cut two strips to finish the armholes') expect(svg).to.contain(content.strings.en.testString)
}) })
}) })

View file

@ -1,8 +1,7 @@
// This file is auto-generated. // This file is auto-generated | Any changes you make will be overwritten.
// Changes you make will be overwritten. import { plugin } from './dist/index.mjs'
import plugin from './dist/index.mjs'
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs' import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
// Run shared tests // Run shared tests
sharedPluginTests(plugin) sharedPluginTests(plugin)