Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
node-version: 22
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
3,769 changes: 1,555 additions & 2,214 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"devDependencies": {
"coveralls": "^3.1.0",
"lerna": "^6.6.1",
"prettier": "^2.1.2",
"prettier": "^3.6.2",
"tap": "^16.3.4",
"tslint": "^6.1.3",
"typescript": "^4.0.3",
"@commitlint/cli": "^17.6.1",
"@commitlint/config-conventional": "^17.6.1"
"typescript": "^5.8.3",
"@commitlint/cli": "^19.8.1",
"@commitlint/config-conventional": "^19.8.1"
}
}
87 changes: 47 additions & 40 deletions packages/cli/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,47 +179,54 @@ export function lintMessageFiles(enOnly: boolean): boolean {
let wordCount = 0;
let characterCount = 0;
const rootDir = helper.getRootDir();
helper.enumerateMsgSync(rootDir, lang, false, function (
// tslint:disable-next-line:no-any
jsonObj: {[key: string]: any},
msgFilePath: string
) {
const jsonObjKeys = Object.keys(jsonObj);
trait.nFiles++;
jsonObjKeys.forEach((key) => {
if (key in trait.msgs) {
trait.dupKeys.push(key);
return;
}
trait.msgs[key] = {};
const trt = trait.msgs[key];
const msg = jsonObj[key];
trt.length = undefined;
if (typeof msg === 'string') {
if (lang === helper.ENGLISH) {
msgCount++;
wordCount += wc(msg);
characterCount += msg.length;
helper.enumerateMsgSync(
rootDir,
lang,
false,
function (
// tslint:disable-next-line:no-any
jsonObj: {[key: string]: any},
msgFilePath: string
) {
const jsonObjKeys = Object.keys(jsonObj);
trait.nFiles++;
jsonObjKeys.forEach((key) => {
if (key in trait.msgs) {
trait.dupKeys.push(key);
return;
}
trt.length = msg.length;
trt.cDoubleLeftBraces = (msg.match(/{{/g) || []).length;
trt.cDoubleRightBraces = (msg.match(/}}/g) || []).length;
trt.hardCoded = msg.match(/{{.+?}}/g);
trt.cHardCoded = trt.hardCoded ? trt.hardCoded.length : 0;
trt.phKeys = [];
let trimedMsg = msg.trim().replace(/{{/g, '').replace(/}}/g, '');
const phs = trimedMsg.match(/{[0-9a-zA-Z]+?}/g);
if (phs)
phs.forEach(function (ph) {
const phKey = ph.slice(1, -1);
trimedMsg = trimedMsg.replace(ph, phKey);
trt.phKeys!.push(phKey);
});
trt.phLeftOrphans = trimedMsg.match(/{[0-9a-zA-Z]+?[^0-9a-zA-Z}]/g);
trt.phRightOrphans = trimedMsg.match(/[^{0-9a-zA-Z][0-9a-zA-Z]+?}/g);
}
});
});
trait.msgs[key] = {};
const trt = trait.msgs[key];
const msg = jsonObj[key];
trt.length = undefined;
if (typeof msg === 'string') {
if (lang === helper.ENGLISH) {
msgCount++;
wordCount += wc(msg);
characterCount += msg.length;
}
trt.length = msg.length;
trt.cDoubleLeftBraces = (msg.match(/{{/g) || []).length;
trt.cDoubleRightBraces = (msg.match(/}}/g) || []).length;
trt.hardCoded = msg.match(/{{.+?}}/g);
trt.cHardCoded = trt.hardCoded ? trt.hardCoded.length : 0;
trt.phKeys = [];
let trimedMsg = msg.trim().replace(/{{/g, '').replace(/}}/g, '');
const phs = trimedMsg.match(/{[0-9a-zA-Z]+?}/g);
if (phs)
phs.forEach(function (ph) {
const phKey = ph.slice(1, -1);
trimedMsg = trimedMsg.replace(ph, phKey);
trt.phKeys!.push(phKey);
});
trt.phLeftOrphans = trimedMsg.match(/{[0-9a-zA-Z]+?[^0-9a-zA-Z}]/g);
trt.phRightOrphans = trimedMsg.match(
/[^{0-9a-zA-Z][0-9a-zA-Z]+?}/g
);
}
});
}
);
if (lang === helper.ENGLISH)
console.log(
'--- linted',
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ function writeAllToMsg(lang: string, json: AnyObject) {
export function getCredentials() {
let LC;
try {
LC = require(path.join(
os.homedir(),
'.strong-globalize/ibm-cloud-credentials.json'
));
LC = require(
path.join(os.homedir(), '.strong-globalize/ibm-cloud-credentials.json')
);
} catch (e) {
// Ignore error
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/test-extract-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var targets = {
err: [
'*** json read failure: /data/dataNonExistent.json *** defined in:' +
' /index.js\n',
'*** key array parse failure: undefined *** defined in: /index.js\n',
'*** key array parse failure: \u001b[90mundefined\u001b[39m *** defined in: /index.js\n',
'*** key array parse failure: [[][ *** defined in: /index.js\n',
],
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/test-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ var targets = {
'3333333333333333333333333333333333333333333333333333333333333333' +
'3333333333333333333333333333333333333333333333333333333333333333' +
'333333333333333333333333333333333333333333333333333333333333333' +
' name is longer than 256\n',
'*** null en:msg006Msg4 message is longer than 8192\n',
' name is longer than \u001b[33m256\u001b[39m\n',
'*** null en:msg006Msg4 message is longer than \u001b[33m8192\u001b[39m\n',
'*** English file is malformed. Other languages not checked.\n',
],
},
Expand Down
17 changes: 9 additions & 8 deletions packages/cli/test/test-translate-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
var gpbHelper = require('./gpb-translate-helper');
var test = require('tap').test;

test('test translate error ' + gpbHelper.FAKE_supportedTranslations, function (
t
) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_supportedTranslations, function () {
t.pass();
t.end();
});
});
test(
'test translate error ' + gpbHelper.FAKE_supportedTranslations,
function (t) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_supportedTranslations, function () {
t.pass();
t.end();
});
}
);
32 changes: 19 additions & 13 deletions packages/cli/test/test-translate-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ var skipTranslate =
!process.env.BLUEMIX_INSTANCE;

if (skipTranslate) {
test('skip translate error ' + gpbHelper.FAKE_bundle_uploadStrings, function (
t
) {
t.pass();
t.end();
});
} else {
test('test translate error ' + gpbHelper.FAKE_bundle_uploadStrings, function (
t
) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_bundle_uploadStrings, function () {
test(
'skip translate error ' + gpbHelper.FAKE_bundle_uploadStrings,
function (t) {
t.pass();
t.end();
});
});
}
);
} else {
test(
'test translate error ' + gpbHelper.FAKE_bundle_uploadStrings,
function (t) {
gpbHelper.fakeGpbTest(
t,
gpbHelper.FAKE_bundle_uploadStrings,
function () {
t.pass();
t.end();
}
);
}
);
}
28 changes: 15 additions & 13 deletions packages/cli/test/test-translate-6.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ var skipTranslate =
!process.env.BLUEMIX_INSTANCE;

if (skipTranslate) {
test('skip translate error ' + gpbHelper.FAKE_bundle_getStrings_1, function (
t
) {
t.pass();
t.end();
});
} else {
test('test translate error ' + gpbHelper.FAKE_bundle_getStrings_1, function (
t
) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_bundle_getStrings_1, function () {
test(
'skip translate error ' + gpbHelper.FAKE_bundle_getStrings_1,
function (t) {
t.pass();
t.end();
});
});
}
);
} else {
test(
'test translate error ' + gpbHelper.FAKE_bundle_getStrings_1,
function (t) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_bundle_getStrings_1, function () {
t.pass();
t.end();
});
}
);
}
28 changes: 15 additions & 13 deletions packages/cli/test/test-translate-7.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ var skipTranslate =
!process.env.BLUEMIX_INSTANCE;

if (skipTranslate) {
test('skip translate error ' + gpbHelper.FAKE_bundle_getStrings_2, function (
t
) {
t.pass();
t.end();
});
} else {
test('test translate error ' + gpbHelper.FAKE_bundle_getStrings_2, function (
t
) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_bundle_getStrings_2, function () {
test(
'skip translate error ' + gpbHelper.FAKE_bundle_getStrings_2,
function (t) {
t.pass();
t.end();
});
});
}
);
} else {
test(
'test translate error ' + gpbHelper.FAKE_bundle_getStrings_2,
function (t) {
gpbHelper.fakeGpbTest(t, gpbHelper.FAKE_bundle_getStrings_2, function () {
t.pass();
t.end();
});
}
);
}
42 changes: 23 additions & 19 deletions packages/runtime/src/globalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ export function packMessage(
const variables = percentInKey
? helper.mapArgs(path, args)
: txtWithTwoOrMoreArgs
? helper.repackArgs(args, 1)
: args[1];
? helper.repackArgs(args, 1)
: args[1];
let message = formatMessage(path, variables, lang);
if (withOriginalMsg)
message = {
Expand Down Expand Up @@ -508,24 +508,28 @@ function loadCldr(lang: string) {
'CLDR already loaded for ' + lang
);
const cldrDir = pathUtil.join(__dirname, '..', 'cldr');
helper.enumerateFilesSync(cldrDir, null, ['json'], false, false, function (
content,
filePath
) {
let cldr = null;
try {
cldr = JSON.parse(content);
} catch (e) {
throw new Error('*** CLDR read error on ' + process.platform);
}
const cldrMain: AnyObject = {main: {}};
cldrMain.main[lang] = cldr.main[lang];
STRONGLOOP_GLB.load!(cldrMain);
if (lang === helper.ENGLISH) {
const cldrSupplemental = {supplemental: cldr.supplemental};
STRONGLOOP_GLB.load!(cldrSupplemental);
helper.enumerateFilesSync(
cldrDir,
null,
['json'],
false,
false,
function (content, filePath) {
let cldr = null;
try {
cldr = JSON.parse(content);
} catch (e) {
throw new Error('*** CLDR read error on ' + process.platform);
}
const cldrMain: AnyObject = {main: {}};
cldrMain.main[lang] = cldr.main[lang];
STRONGLOOP_GLB.load!(cldrMain);
if (lang === helper.ENGLISH) {
const cldrSupplemental = {supplemental: cldr.supplemental};
STRONGLOOP_GLB.load!(cldrSupplemental);
}
}
});
);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions packages/util/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ const LANGS = [
// 'zu', // Zulu
];

const cldrVersion = require(path.resolve(
__dirname,
'node_modules/cldr-data/package.json'
)).version;
const cldrVersion = require(
path.resolve(__dirname, 'node_modules/cldr-data/package.json')
).version;
var CLDR = {};

LANGS.forEach(function (lang) {
Expand Down
Loading