vcpkg-tool/vcpkg-artifacts/i18n.ts

73 строки
2.3 KiB
TypeScript
Исходник Обычный вид История

Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/* eslint-disable @typescript-eslint/no-var-requires */
import * as vm from 'vm';
/**
* Creates a reusable safe-eval sandbox to execute code in.
*/
export function createSandbox(): <T>(code: string, context?: any) => T {
const sandbox = vm.createContext({});
return (code: string, context?: any) => {
const response = 'SAFE_EVAL_' + Math.floor(Math.random() * 1000000);
sandbox[response] = {};
if (context) {
Object.keys(context).forEach(key => sandbox[key] = context[key]);
vm.runInContext(`try { ${response} = ${code} } catch (e) { ${response} = undefined }`, sandbox);
for (const key of Object.keys(context)) {
delete sandbox[key];
}
} else {
vm.runInContext(`${response} = ${code}`, sandbox);
}
return sandbox[response];
};
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
}
export const safeEval = createSandbox();
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
type PrimitiveValue = string | number | boolean | undefined | Date;
let currentLocale = require('./locales/messages.json');
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
export function setLocale(newLocale: string | undefined) {
if (newLocale) {
currentLocale = require(newLocale);
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
}
}
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
/**
* generates the translation key for a given message
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
*
* @param literals
* @returns the key
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
*/
function indexOf(literals: TemplateStringsArray) {
const content = literals.flatMap((k, i) => [k, '$']);
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
content.length--; // drop the trailing undefined.
return content.join('').trim().replace(/ [a-z]/g, ([a, b]) => b.toUpperCase()).replace(/[^a-zA-Z$]/g, '');
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
}
/**
* Support for tagged template literals for i18n.
*
* Leverages translation files in ../i18n
*
* @param literals the literal values in the tagged template
* @param values the inserted values in the template
*
* @translator
*/
export function i(literals: TemplateStringsArray, ...values: Array<string | number | boolean | undefined | Date>): string {
const key = indexOf(literals);
if (key) {
const str = currentLocale[key]; // get localized string
if (str) {
// fill out the template string.
return safeEval(`\`${str}\``, values.reduce((p, c, i) => { p[`p${i}`] = c; return p; }, <any>{}));
}
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
}
// if the translation isn't available, just resolve the string template normally.
return String.raw(literals, ...values);
Move vcpkg-ce development into the vcpkg-tool repo. (#428) * Move vcpkg-ce development into the vcpkg-tool repo. This change obsoletes https://github.com/microsoft/vcpkg-ce , which will be archived shortly after this merges. ce development did not maintain a linear history but vcpkg-tool does maintain a linear history, so I have not attempted to preserve "blame". The following files were not copied over: * `.git/**/*` * `.github/**/*` (workflows changes merged into pipelines.yaml) * `.scripts/verify-pr.yaml` * `.scripts/signing/**/*` * `LICENSE.md` * `test/vcpkg-ce.test.build.log` * `azure-pipelines.yml` The following files were modified: * `.vscode/**/*` was placed in the root, had paths rewritten to target the "ce" subdirectory, and a few tasks renamed to indicate that they target the "ce" subset. * `CODE_OF_CONDUCT.md`/`SECURITY.md`/`SUPPORT.md`/`PolicheckExclusion.xml` were placed in the root. * `.gitattributes` was merged with the existing one in the root. * `.gitignore` had a few things explicitly copied into the root but most were discarded. * `readme.md` had some content merged. * Add missing gitignores * Remove broken fast-xml-parser reference. * Fix some more vcpkg-ce names. * Fix some repo docs. * Add back overzealous vcpkg- removal for vcpkg-init. * Delete support.md as it's irrelevant in the tool repo. * Replay https://github.com/microsoft/vcpkg-ce/pull/22/ * Remove big test assets. * Update ce/getting-started.md Co-authored-by: Robert Schumacher <roschuma@microsoft.com> * Delete 'docs' folder. Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
2022-03-23 03:07:57 +03:00
}