Skip to content

Commit 7061f16

Browse files
authored
Merge pull request #3211 from sjiang-cb/g11n-js-client
Make HttpRequestOptions accept 'headers' parameter when Axios request.
2 parents a55c551 + 2eb32c1 commit 7061f16

File tree

12 files changed

+5851
-5976
lines changed

12 files changed

+5851
-5976
lines changed

.github/workflows/node.js.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
pre-process:
1414
name: Pre process
1515
runs-on: ubuntu-latest
16-
outputs:
16+
outputs:
1717
were-only-docs-updated: ${{ steps.were-only-docs-updated-action.outputs.were-only-docs-updated }}
1818
steps:
1919
- name: Checkout code
@@ -38,7 +38,7 @@ jobs:
3838
- name: Checkout code
3939
uses: actions/checkout@v2
4040
with:
41-
fetch-depth: 2.
41+
fetch-depth: 2.
4242
- name: Get commit range
4343
id: get-commit-range-action
4444
uses: ./.github/actions/get-commit-range-action
@@ -86,50 +86,50 @@ jobs:
8686
security-events: write
8787
strategy:
8888
matrix:
89-
node-version: [10.x]
89+
node-version: [14.x]
9090
steps:
9191
- name: Checkout repository
9292
uses: actions/checkout@v2
9393
- name: Create cache folder
9494
run: |
9595
mkdir -p /home/runner/.npm
96-
continue-on-error: true
96+
continue-on-error: true
9797
- name: Use Node.js ${{ matrix.node-version }}
9898
uses: actions/setup-node@v2
9999
with:
100100
node-version: ${{ matrix.node-version }}
101-
cache: 'npm'
101+
cache: 'npm'
102102
- name: Initialize CodeQL
103-
uses: github/codeql-action/init@v1
103+
uses: github/codeql-action/init@v2
104104
with:
105105
languages: javascript
106106
- name: Autobuild
107-
uses: github/codeql-action/autobuild@v1
107+
uses: github/codeql-action/autobuild@v2
108108
- name: Perform CodeQL Analysis
109-
uses: github/codeql-action/analyze@v1
110-
109+
uses: github/codeql-action/analyze@v2
110+
111111
codacy-analysis-cli:
112112
name: Codacy Analysis CLI
113113
runs-on: ubuntu-latest
114114
steps:
115115
- name: Checkout code
116116
uses: actions/checkout@main
117117
- name: Run Codacy Analysis CLI
118-
uses: codacy/codacy-analysis-cli-action@master
118+
uses: codacy/codacy-analysis-cli-action@master
119119
with:
120120
output: results.sarif
121121
format: sarif
122122
# Adjust severity of non-security issues
123123
gh-code-scanning-compat: true
124124
# Force 0 exit code to allow SARIF file generation
125125
# This will handover control about PR rejection to the GitHub side
126-
max-allowed-issues: 2147483647
127-
# Upload the SARIF file generated in the previous step
126+
max-allowed-issues: 2147483647
127+
# Upload the SARIF file generated in the previous step
128128
- name: Upload SARIF results file
129129
uses: github/codeql-action/upload-sarif@main
130130
with:
131131
sarif_file: results.sarif
132-
132+
133133
smoke-test:
134134
name: Smoke Test
135135
runs-on: ubuntu-latest
@@ -141,19 +141,19 @@ jobs:
141141
steps:
142142
- name: Checkout code
143143
uses: actions/checkout@v2
144-
- name: Set up JDK 8
144+
- name: Set up JDK 17
145145
uses: actions/setup-java@v2
146146
with:
147147
distribution: 'adopt'
148-
java-version: '8'
148+
java-version: '17'
149149
- name: Use Node.js ${{ matrix.node-version }}
150150
uses: actions/setup-node@v2
151151
with:
152152
node-version: ${{ matrix.node-version }}
153153
cache: 'npm'
154154
- name: Smoke Test
155155
run: |
156-
TZ='Asia/Shanghai'; export TZ
156+
TZ='Asia/Shanghai'; export TZ
157157
mkdir -p g11n-js-client
158158
shopt -s extglob
159159
mv !(g11n-js-client) g11n-js-client/

jest.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"json"
88
],
99
"testRegex": "/test/*.*\\.spec\\.ts$",
10+
"testEnvironment": "jsdom",
1011
"transform": {
1112
"^.+\\.tsx?$": "ts-jest"
1213
},

package-lock.json

Lines changed: 5762 additions & 5915 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.client.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@singleton-i18n/js-core-sdk",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"publishConfig": {
55
"registry": ""
66
},
@@ -42,18 +42,26 @@
4242
"@types/node": "^10.11.7",
4343
"awesome-typescript-loader": "^5.2.1",
4444
"axios": "^0.21.1",
45-
"jest": "^24.5.0",
46-
"ts-jest": "^24.0.0",
45+
"jest": "^29.7.0",
46+
"jest-environment-jsdom": "^28.1.3",
47+
"ts-jest": "^29.2.5",
4748
"ts-node": "^7.0.1",
4849
"tslint": "^5.11.0",
4950
"tslint-loader": "^3.5.4",
5051
"typescript": "^4.4.4",
51-
"typescript-loader": "^1.1.3",
52-
"typings": "^2.1.1",
53-
"webpack": "^4.20.2",
54-
"webpack-cli": "^3.3.0"
52+
"webpack": "^5.96.1",
53+
"webpack-cli": "^5.1.4"
5554
},
5655
"changelogHistory": [
56+
{
57+
"date": "11/15/24",
58+
"version": "0.5.8",
59+
"notes": [
60+
{
61+
"description": "Make HttpRequestOptions accept 'headers' parameter when Axios request."
62+
}
63+
]
64+
},
5765
{
5866
"date": "06/05/23",
5967
"version": "0.5.7",

package.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@singleton-i18n/js-core-sdk-server",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"publishConfig": {
55
"registry": ""
66
},
@@ -42,18 +42,26 @@
4242
"@types/node": "^10.11.7",
4343
"awesome-typescript-loader": "^5.2.1",
4444
"axios": "^0.21.1",
45-
"jest": "^24.5.0",
46-
"ts-jest": "^24.0.0",
45+
"jest": "^29.7.0",
46+
"jest-environment-jsdom": "^28.1.3",
47+
"ts-jest": "^29.2.5",
4748
"ts-node": "^7.0.1",
4849
"tslint": "^5.11.0",
4950
"tslint-loader": "^3.5.4",
5051
"typescript": "^4.4.4",
51-
"typescript-loader": "^1.1.3",
52-
"typings": "^2.1.1",
53-
"webpack": "^4.20.2",
54-
"webpack-cli": "^3.3.0"
52+
"webpack": "^5.96.1",
53+
"webpack-cli": "^5.1.4"
5554
},
5655
"changelogHistory": [
56+
{
57+
"date": "11/15/24",
58+
"version": "0.5.8",
59+
"notes": [
60+
{
61+
"description": "Make HttpRequestOptions accept 'headers' parameter when Axios request."
62+
}
63+
]
64+
},
5765
{
5866
"date": "06/05/23",
5967
"version": "0.5.7",

samples/client/js/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"load-translation": "load-translation --directory `pwd`/src/sources --product CoreSDKClient --component ui --host http://localhost:8091 --version 1.0 --languages zh,en"
1111
},
1212
"dependencies": {
13-
"@singleton-i18n/js-core-sdk": "file:../../../singleton-i18n-js-core-sdk-0.5.7.tgz",
13+
"@singleton-i18n/js-core-sdk": "file:../../../singleton-i18n-js-core-sdk-0.5.8.tgz",
1414
"argparse": "^1.0.10",
1515
"axios": "^0.21.1",
1616
"typescript": "^4.4.4"
@@ -21,8 +21,11 @@
2121
"copy-webpack-plugin": "^5.0.4",
2222
"express": "^4.17.1",
2323
"express-rate-limit": "^6.7.0",
24-
"jest": "^24.9.0",
25-
"webpack": "^4.39.1",
26-
"webpack-cli": "^3.3.6"
24+
"jest": "^29.7.0",
25+
"webpack": "^5.96.1",
26+
"webpack-cli": "^5.1.4"
27+
},
28+
"jest": {
29+
"testEnvironment": "jsdom"
2730
}
2831
}

samples/client/js/src/i18n.utils.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2024 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
import * as singletonCore from '@singleton-i18n/js-core-sdk';
66
import { ENGLISH } from './source.l10n';
77
import { config as defaultConfig } from './config';
88

99
/**
10-
* Should be executed in the html file that needs to be localized.
11-
*
10+
* Should be executed in the html file that needs to be localized.
11+
*
1212
* @param {*} config object that provides the configuration with the following format
1313
* {
14-
* productID, version, component, host, localizeAttribute, langCookieName, localStoragePseudoKey
15-
* }
14+
* productID, version, component, host, localizeAttribute, langCookieName, localStoragePseudoKey
15+
* }
1616
*/
1717
export function localize(config) {
1818

1919
config = config ? config : {};
20-
// If some properties aren't provided by the given config
20+
// If some properties aren't provided by the given config
2121
// we are getting them from the defaultConfig
2222
config = Object.assign(defaultConfig, config);
2323
const lang = detectLanguage(config);
@@ -39,16 +39,20 @@ export function localize(config) {
3939
language: lang,
4040
sourceBundle: ENGLISH,
4141
// Uncommend if you don't want to load your translation from singleton but from your sources
42-
//i18nAssets: 'src/translations/',
42+
//i18nAssets: 'src/translations/',
4343
isPseudo: shouldUsePseudoTranslations(),
44+
// It offers the feature to self-custom header for target product
45+
httpOptions: {
46+
headers: {'vrni-header': 'vrni_custom'}
47+
}
4448
}
4549
);
4650
loadAndShowTranslations(i18nClient, config);
4751
}
4852

4953
/**
50-
* Collects all elements from the page that have the l10n attribute.
51-
* Gets the attribute's value which is the key for the message, localizes the message
54+
* Collects all elements from the page that have the l10n attribute.
55+
* Gets the attribute's value which is the key for the message, localizes the message
5256
* and inserts it in the element.
5357
*/
5458
function loadAndShowTranslations(i18nClient, config) {
@@ -65,12 +69,12 @@ function loadAndShowTranslations(i18nClient, config) {
6569
}
6670

6771
/**
68-
* Function that gets the current language.
69-
* If not set in the cookies it tries to detect the browser's.
70-
* If the browser's language isn't supported by singleton, falls back to english.
72+
* Function that gets the current language.
73+
* If not set in the cookies it tries to detect the browser's.
74+
* If the browser's language isn't supported by singleton, falls back to english.
7175
*/
7276
function detectLanguage(config) {
73-
// First checks for lang in the cookie
77+
// First checks for lang in the cookie
7478
let language = getCookie(config.langCookieName);
7579
if (language) {
7680
return language;
@@ -81,8 +85,8 @@ function detectLanguage(config) {
8185
return language || undefined;
8286
}
8387

84-
/**
85-
* Gets a cookie by its name.
88+
/**
89+
* Gets a cookie by its name.
8690
*/
8791
function getCookie(name) {
8892
function escape(s) { return s.replace(/([.*+?\^${}()|\[\]\/\\])/g, '\\$1'); };

samples/server/express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"collect-source-bundle": "collect-source-bundle --source-dir `pwd`/i18n --product NodeSample --component NodeJS --host http://localhost:8091 --version 1.0"
99
},
1010
"dependencies": {
11-
"@singleton-i18n/js-core-sdk-server": "file:../../../singleton-i18n-js-core-sdk-server-0.5.7.tgz",
11+
"@singleton-i18n/js-core-sdk-server": "file:../../../singleton-i18n-js-core-sdk-server-0.5.8.tgz",
1212
"argparse": "^1.0.10",
1313
"axios": "^0.21.1",
1414
"express": "4.15.3",

src/formatters/plural/plural.formatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2024 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
import { PLURALFUNCS } from './plurals.func';
@@ -8,7 +8,7 @@ export class Plural {
88
constructor() { }
99
private resolveLocale(locale: string): string {
1010
let lang: string = locale;
11-
do {
11+
do {
1212
if (PLURALFUNCS[lang]) {
1313
return lang;
1414
} else if (PLURALFUNCS[lang.toLocaleLowerCase()]) {

src/loader.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2021 VMware, Inc.
2+
* Copyright 2019-2024 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
import axios from 'axios';
@@ -8,6 +8,11 @@ import { basedLogger, Logger } from './logger';
88
export interface HttpRequestOptions {
99
timeout?: number;
1010
withCredentials?: boolean;
11+
headers?: HttpHeaders;
12+
}
13+
14+
export interface HttpHeaders {
15+
[key: string]: string;
1116
}
1217

1318
export abstract class Loader {

0 commit comments

Comments
 (0)