Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
feat: Retrieving translations from scanner and CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly authored and fabnguess committed Jul 27, 2024
2 parents e38451b + b794525 commit df6ddef
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 31 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
uses: github/codeql-action/init@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -60,7 +60,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
uses: github/codeql-action/autobuild@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -73,6 +73,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
uses: github/codeql-action/analyze@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
with:
category: "/language:${{matrix.language}}"
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
fail-fast: false
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # v2.3.3
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -64,14 +64,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
uses: github/codeql-action/upload-sarif@f079b8493333aace61c81488f8bd40919487bd9f # v3.25.7
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 NodeSecure
Copyright (c) 2021-2024 NodeSecure

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion i18n/cli/english.js → externalLanguages/cli/english.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-len */
// Import Third-party Dependencies
import { taggedString as tS } from "@nodesecure/i18n";
import { taggedString as tS } from "../../src/utils.js";

const cli = {
executing_at: "Executing node-secure at",
Expand Down
2 changes: 1 addition & 1 deletion i18n/cli/french.js → externalLanguages/cli/french.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-len */
// Import Third-party Dependencies
import { taggedString as tS } from "@nodesecure/i18n";
import { taggedString as tS } from "../../src/utils.js";

const cli = {
executing_at: "Exécution de node-secure à",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare namespace i18n {
export function getToken(token: string, ...parameters): Promise<string>;
export function getTokenSync(token: string, ...parameters): string;
export function getLanguages(): Promise<languages[]>;
export function taggedString(str: string, ...keys: any[]): (...keys: any[]) => string;
export function taggedString(str: string | TemplateStringsArray, ...keys: any[]): (...keys: any[]) => string;
export function extend(language: string, tokens: Record<string, any>): void;
export function extendFromSystemPath(path: string): Promise<void>;
export function getAllTranslations(): Promise<object>;
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ export async function extendFromSystemPath(languagesDirPath) {
}
}

export async function getAllTranslations(){
export async function getAllTranslations() {
return languages;
}
4 changes: 2 additions & 2 deletions languages/english.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable max-len */

// Require Internal Dependencies
import { cli } from "../i18n/cli/english.js";
import { scanner } from "../i18n/scanner/english.js";
import cli from "../externalLanguages/cli/english.js";
import scanner from "../externalLanguages/scanner/english.js";
import { taggedString as tS } from "../src/utils.js";

const lang = "en";
Expand Down
4 changes: 2 additions & 2 deletions languages/french.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable max-len */

// Import Internal Dependencies
import { cli } from "../i18n/cli/french.js";
import { scanner } from "../i18n/scanner/french.js";
import cli from "../externalLanguages/cli/french.js";
import scanner from "../externalLanguages/scanner/french.js";
import { taggedString as tS } from "../src/utils.js";

const lang = "fr";
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodesecure/i18n",
"version": "3.6.0",
"version": "4.0.1",
"description": "NodeSecure Internationalization",
"exports": "./index.js",
"scripts": {
Expand Down Expand Up @@ -34,8 +34,8 @@
"devDependencies": {
"@nodesecure/eslint-config": "^1.8.0",
"@nodesecure/github": "^1.2.0",
"c8": "^8.0.1",
"zup": "^0.0.1"
"c8": "^10.1.2",
"zup": "^0.0.2"
},
"type": "module",
"engines": {
Expand Down
26 changes: 20 additions & 6 deletions scripts/fetchi18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@ const repos = {
for (const [repo, i18nFolderPath] of Object.entries(repos)) {
const { location } = await github.downloadAndExtract(`NodeSecure.${repo}`, { branch: "master" });
const i18nPath = path.join(location, i18nFolderPath);

console.log(styleText(["bold", "green"], `[INFO]`), `i18nPath: ${i18nPath}`);

const french = fs.readFileSync(path.join(i18nPath, "french.js"), "utf-8");
const english = fs.readFileSync(path.join(i18nPath, "english.js"), "utf-8");

const frenchFilePath = path.join(process.cwd(), "i18n", repo, "french.js");
const englishFilePath = path.join(process.cwd(), "i18n", repo, "english.js");

fs.writeFileSync(frenchFilePath, french);
fs.writeFileSync(englishFilePath, english);
const frenchFilePath = path.join(process.cwd(), "externalLanguages", repo, "french.js");
const englishFilePath = path.join(process.cwd(), "externalLanguages", repo, "english.js");

fs.mkdirSync(path.dirname(frenchFilePath), { recursive: true });
fs.mkdirSync(path.dirname(englishFilePath), { recursive: true });

if (repo === "cli") {
fs.writeFileSync(frenchFilePath, french.replace(
"import { taggedString as tS } from \"@nodesecure/i18n\";",
"import { taggedString as tS } from \"../../src/utils.js\";"
)),
fs.writeFileSync(englishFilePath, english.replace(
"import { taggedString as tS } from \"@nodesecure/i18n\";",
"import { taggedString as tS } from \"../../src/utils.js\";"
));
} else {
fs.writeFileSync(frenchFilePath, french);
fs.writeFileSync(englishFilePath, english);
}

fs.rmSync(location, { recursive: true, force: true });
}
Expand Down

0 comments on commit df6ddef

Please sign in to comment.