Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all traces of crowdin branch support #9964

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
16 changes: 1 addition & 15 deletions cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2539,9 +2539,7 @@ async function buildTargetCoreAsync(options: BuildTargetOptions = {}) {
tag: info.tag,
commits: info.commitUrl,
target: readJson("package.json")["version"],
pxt: pxtVersion(),
pxtCrowdinBranch: pxtCrowdinBranch(),
targetCrowdinBranch: targetCrowdinBranch()
pxt: pxtVersion()
}
saveThemeJson(cfg, options.localDir, options.packaged)
fillInCompilerExtension(cfg);
Expand Down Expand Up @@ -2610,18 +2608,6 @@ function pxtVersion(): string {
readJson("node_modules/pxt-core/package.json")["version"];
}

function pxtCrowdinBranch(): string {
const theme = pxt.appTarget.id == "core" ?
readJson("pxtarget.json").appTheme :
readJson("node_modules/pxt-core/pxtarget.json").appTheme;
return theme ? theme.crowdinBranch : undefined;
}

function targetCrowdinBranch(): string {
const theme = readJson("pxtarget.json").appTheme;
return theme ? theme.crowdinBranch : undefined;
}

function buildAndWatchAsync(f: () => Promise<string[]>, maxDepth: number): Promise<void> {
let currMtime = Date.now()
return f()
Expand Down
1 change: 0 additions & 1 deletion localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ declare namespace pxt {
hasAudio?: boolean; // target uses the Audio manager. if true: a mute button is added to the simulator toolbar.
crowdinProject?: string;
crowdinProjectId?: number; // Crowdin project id. Can be found by going to the project page in Crowdin and selecting Tools > API
crowdinBranch?: string; // optional branch specification for localization files
monacoToolbox?: boolean; // if true: show the monaco toolbox when in the monaco editor
blockHats?: boolean; // if true, event blocks have hats
allowParentController?: boolean; // allow parent iframe to control editor
Expand Down
2 changes: 0 additions & 2 deletions localtypings/pxtpackage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ declare namespace pxt {
targetId?: string;
targetWebsite?: string;
pxt?: string;
pxtCrowdinBranch?: string;
targetCrowdinBranch?: string;
tag?: string;
branch?: string;
commits?: string; // URL
Expand Down
40 changes: 20 additions & 20 deletions pxtlib/browserutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ namespace pxt.BrowserUtils {
console.log(`adding entry ${md.length * 2} bytes`);
return U.delay(1)
.then(() => translationDbAsync())
.then(db => db.setAsync("foobar", Math.random().toString(), "", null, undefined, md))
.then(db => db.setAsync("foobar", Math.random().toString(), null, undefined, md))
.then(() => pxt.BrowserUtils.storageEstimateAsync())
.then(estimate => !estimate.quota || estimate.usage / estimate.quota < 0.8 ? stressTranslationsAsync() : Promise.resolve());
}
Expand All @@ -787,33 +787,33 @@ namespace pxt.BrowserUtils {
}

export interface ITranslationDb {
getAsync(lang: string, filename: string, branch: string): Promise<ITranslationDbEntry>;
setAsync(lang: string, filename: string, branch: string, etag: string, strings?: pxt.Map<string>, md?: string): Promise<void>;
getAsync(lang: string, filename: string): Promise<ITranslationDbEntry>;
setAsync(lang: string, filename: string, etag: string, strings?: pxt.Map<string>, md?: string): Promise<void>;
// delete all
clearAsync(): Promise<void>;
}

class MemTranslationDb implements ITranslationDb {
translations: pxt.Map<ITranslationDbEntry> = {};
key(lang: string, filename: string, branch: string) {
return `${lang}|${filename}|${branch || "master"}`;
key(lang: string, filename: string) {
return `${lang}|${filename}|master`;
}
get(lang: string, filename: string, branch: string): ITranslationDbEntry {
return this.translations[this.key(lang, filename, branch)];
get(lang: string, filename: string): ITranslationDbEntry {
return this.translations[this.key(lang, filename)];
}
getAsync(lang: string, filename: string, branch: string): Promise<ITranslationDbEntry> {
return Promise.resolve(this.get(lang, filename, branch));
getAsync(lang: string, filename: string): Promise<ITranslationDbEntry> {
return Promise.resolve(this.get(lang, filename));
}
set(lang: string, filename: string, branch: string, etag: string, time: number, strings?: pxt.Map<string>, md?: string) {
this.translations[this.key(lang, filename, branch)] = {
set(lang: string, filename: string, etag: string, time: number, strings?: pxt.Map<string>, md?: string) {
this.translations[this.key(lang, filename)] = {
etag,
time,
strings,
md
}
}
setAsync(lang: string, filename: string, branch: string, etag: string, strings?: pxt.Map<string>, md?: string): Promise<void> {
this.set(lang, filename, branch, etag, Util.now(), strings);
setAsync(lang: string, filename: string, etag: string, strings?: pxt.Map<string>, md?: string): Promise<void> {
this.set(lang, filename, etag, Util.now(), strings);
return Promise.resolve();
}
clearAsync() {
Expand Down Expand Up @@ -1011,17 +1011,17 @@ namespace pxt.BrowserUtils {
this.db = db;
this.mem = new MemTranslationDb();
}
getAsync(lang: string, filename: string, branch: string): Promise<ITranslationDbEntry> {
getAsync(lang: string, filename: string): Promise<ITranslationDbEntry> {
lang = (lang || "en-US").toLowerCase(); // normalize locale
const id = this.mem.key(lang, filename, branch);
const r = this.mem.get(lang, filename, branch);
const id = this.mem.key(lang, filename);
const r = this.mem.get(lang, filename);
if (r) return Promise.resolve(r);

return this.db.getAsync<ITranslationDbEntry>(IndexedDbTranslationDb.TABLE, id)
.then((res) => {
if (res) {
// store in-memory so that we don't try to download again
this.mem.set(lang, filename, branch, res.etag, res.time, res.strings);
this.mem.set(lang, filename, res.etag, res.time, res.strings);
return Promise.resolve(res);
}
return Promise.resolve(undefined);
Expand All @@ -1030,11 +1030,11 @@ namespace pxt.BrowserUtils {
return Promise.resolve(undefined);
});
}
setAsync(lang: string, filename: string, branch: string, etag: string, strings?: pxt.Map<string>, md?: string): Promise<void> {
setAsync(lang: string, filename: string, etag: string, strings?: pxt.Map<string>, md?: string): Promise<void> {
lang = (lang || "en-US").toLowerCase(); // normalize locale
const id = this.mem.key(lang, filename, branch);
const id = this.mem.key(lang, filename);
let time = Util.now();
this.mem.set(lang, filename, branch, etag, time, strings, md);
this.mem.set(lang, filename, etag, time, strings, md);

if (strings) {
Object.keys(strings).filter(k => !strings[k]).forEach(k => delete strings[k]);
Expand Down
5 changes: 2 additions & 3 deletions pxtlib/emitter/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,16 @@ namespace pxt.Cloud {
const FORCE_MARKDOWN_UPDATE = MARKDOWN_EXPIRATION * 24 * 7;

locale = locale || pxt.Util.userLanguage();
const branch = "";

const db = await pxt.BrowserUtils.translationDbAsync();
const entry = await db.getAsync(locale, docid, branch);
const entry = await db.getAsync(locale, docid);

const downloadAndSetMarkdownAsync = async () => {
try {
const r = await downloadMarkdownAsync(docid, locale, entry?.etag);
// TODO directly compare the entry/response etags after backend change
if (!entry || (r.md && entry.md !== r.md)) {
await db.setAsync(locale, docid, branch, r.etag, undefined, r.md);
await db.setAsync(locale, docid, r.etag, undefined, r.md);
return r.md;
}
return entry.md;
Expand Down
2 changes: 1 addition & 1 deletion pxtlib/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ namespace pxt {
if (pxt.Util.liveLocalizationEnabled() && this.id != "this" && pxt.appTarget.bundledpkgs[this.id]) {
pxt.debug(`loading live translations for ${this.id}`)
return Promise.all(filenames.map(
fn => pxt.Util.downloadLiveTranslationsAsync(lang, `${targetId}/${fn}-strings.json`, theme.crowdinBranch)
fn => pxt.Util.downloadLiveTranslationsAsync(lang, `${targetId}/${fn}-strings.json`)
.then(tr => {
if (tr && Object.keys(tr).length) {
Util.jsonMergeFrom(r, tr);
Expand Down
39 changes: 16 additions & 23 deletions pxtlib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,14 +1120,13 @@ namespace ts.pxtc.Util {
return f() + f() + "-" + f() + "-4" + f().slice(-3) + "-" + f() + "-" + f() + f() + f();
}

export function downloadLiveTranslationsAsync(lang: string, filename: string, branch?: string, etag?: string): Promise<pxt.Map<string>> {
export function downloadLiveTranslationsAsync(lang: string, filename: string, etag?: string): Promise<pxt.Map<string>> {
// hitting the cloud
function downloadFromCloudAsync(strings?: pxt.Map<string>) {
pxt.debug(`downloading translations for ${lang} ${filename} ${branch || ""}`);
pxt.debug(`downloading translations for ${lang} ${filename}`);
let host = pxt.BrowserUtils.isLocalHost() || pxt.webConfig.isStatic ? "https://makecode.com/api/" : ""
// https://pxt.io/api/translations?filename=strings.json&lang=pl&approved=true&branch=v0
// https://pxt.io/api/translations?filename=strings.json&lang=pl&approved=true
let url = `${host}translations?lang=${encodeURIComponent(lang)}&filename=${encodeURIComponent(filename)}&approved=true`;
if (branch) url += '&branch=' + encodeURIComponent(branch);
const headers: pxt.Map<string> = {};
if (etag && !pxt.Cloud.useCdnApi()) headers["If-None-Match"] = etag;
return (host ? requestAsync : pxt.Cloud.apiRequestWithCdnAsync)({ url, headers }).then(resp => {
Expand All @@ -1136,7 +1135,7 @@ namespace ts.pxtc.Util {
// store etag and translations
etag = resp.headers["etag"] as string || "";
return pxt.BrowserUtils.translationDbAsync()
.then(db => db.setAsync(lang, filename, branch, etag, resp.json || strings))
.then(db => db.setAsync(lang, filename, etag, resp.json || strings))
.then(() => resp.json || strings);
}

Expand All @@ -1149,7 +1148,7 @@ namespace ts.pxtc.Util {

// check for cache
return pxt.BrowserUtils.translationDbAsync()
.then(db => db.getAsync(lang, filename, branch))
.then(db => db.getAsync(lang, filename))
.then((entry: pxt.BrowserUtils.ITranslationDbEntry) => {
// if cached, return immediately
if (entry) {
Expand Down Expand Up @@ -1278,17 +1277,13 @@ namespace ts.pxtc.Util {
targetId: string;
baseUrl: string;
code: string;
pxtBranch: string;
targetBranch: string;
force?: boolean;
}

export function updateLocalizationAsync(opts: LocalizationUpdateOptions): Promise<void> {
const {
targetId,
baseUrl,
pxtBranch,
targetBranch,
force,
} = opts;
let { code } = opts;
Expand All @@ -1303,8 +1298,7 @@ namespace ts.pxtc.Util {
pxt.debug(`loc: ${code}`);

const liveUpdateStrings = pxt.Util.liveLocalizationEnabled()
return downloadTranslationsAsync(targetId, baseUrl, code,
pxtBranch, targetBranch, liveUpdateStrings,
return downloadTranslationsAsync(targetId, baseUrl, code, liveUpdateStrings,
ts.pxtc.Util.TranslationsKind.Editor)
.then((translations) => {
if (translations) {
Expand All @@ -1315,8 +1309,7 @@ namespace ts.pxtc.Util {

// Download api translations
return ts.pxtc.Util.downloadTranslationsAsync(
targetId, baseUrl, code,
pxtBranch, targetBranch, liveUpdateStrings,
targetId, baseUrl, code, liveUpdateStrings,
ts.pxtc.Util.TranslationsKind.Apis)
.then(trs => {
if (trs)
Expand All @@ -1332,7 +1325,7 @@ namespace ts.pxtc.Util {
SkillMap
}

export function downloadTranslationsAsync(targetId: string, baseUrl: string, code: string, pxtBranch: string, targetBranch: string, live: boolean, translationKind?: TranslationsKind): Promise<pxt.Map<string>> {
export function downloadTranslationsAsync(targetId: string, baseUrl: string, code: string, live: boolean, translationKind?: TranslationsKind): Promise<pxt.Map<string>> {
translationKind = translationKind || TranslationsKind.Editor;
code = normalizeLanguageCode(code)[0];
if (code === "en-US" || code === "en") // shortcut
Expand All @@ -1343,22 +1336,22 @@ namespace ts.pxtc.Util {
return Promise.resolve(translationsCache()[translationsCacheId]);
}

let stringFiles: { branch: string, staticName: string, path: string }[];
let stringFiles: { staticName: string, path: string }[];
switch (translationKind) {
case TranslationsKind.Editor:
stringFiles = [
{ branch: pxtBranch, staticName: "strings.json", path: "strings.json" },
{ branch: targetBranch, staticName: "target-strings.json", path: targetId + "/target-strings.json" },
{ staticName: "strings.json", path: "strings.json" },
{ staticName: "target-strings.json", path: targetId + "/target-strings.json" },
];
break;
case TranslationsKind.Sim:
stringFiles = [{ branch: targetBranch, staticName: "sim-strings.json", path: targetId + "/sim-strings.json" }];
stringFiles = [{ staticName: "sim-strings.json", path: targetId + "/sim-strings.json" }];
break;
case TranslationsKind.Apis:
stringFiles = [{ branch: targetBranch, staticName: "bundled-strings.json", path: targetId + "/bundled-strings.json" }];
stringFiles = [{ staticName: "bundled-strings.json", path: targetId + "/bundled-strings.json" }];
break;
case TranslationsKind.SkillMap:
stringFiles = [{ branch: targetBranch, staticName: "skillmap-strings.json", path: "/skillmap-strings.json" }];
stringFiles = [{ staticName: "skillmap-strings.json", path: "/skillmap-strings.json" }];
break;
}
let translations: pxt.Map<string>;
Expand All @@ -1375,7 +1368,7 @@ namespace ts.pxtc.Util {
if (live) {
let errorCount = 0;

const pAll = U.promiseMapAllSeries(stringFiles, (file) => downloadLiveTranslationsAsync(code, file.path, file.branch)
const pAll = U.promiseMapAllSeries(stringFiles, (file) => downloadLiveTranslationsAsync(code, file.path)
.then(mergeTranslations, e => {
console.log(e.message);
++errorCount;
Expand All @@ -1391,7 +1384,7 @@ namespace ts.pxtc.Util {
if (errorCount === stringFiles.length || !translations) {
// Retry with non-live translations by setting live to false
pxt.tickEvent("translations.livetranslationsfailed");
return downloadTranslationsAsync(targetId, baseUrl, code, pxtBranch, targetBranch, false, translationKind);
return downloadTranslationsAsync(targetId, baseUrl, code, false, translationKind);
}

return Promise.resolve(translations);
Expand Down
6 changes: 1 addition & 5 deletions pxtrunner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ function initInnerAsync() {
targetId: pxt.appTarget.id,
baseUrl: cfg.commitCdnUrl,
code: lang,
pxtBranch: versions ? versions.pxtCrowdinBranch : "",
targetBranch: versions ? versions.targetCrowdinBranch : "",
force: force,
})
.then(() => initHost())
Expand Down Expand Up @@ -605,9 +603,7 @@ export function setEditorContextAsync(mode: LanguageMode, localeInfo: string) {
return pxt.Util.updateLocalizationAsync({
targetId: pxt.appTarget.id,
baseUrl: pxt.webConfig.commitCdnUrl,
code: localeInfo.replace(localeLiveRx, ''),
pxtBranch: pxt.appTarget.versions.pxtCrowdinBranch,
targetBranch: pxt.appTarget.versions.targetCrowdinBranch,
code: localeInfo.replace(localeLiveRx, '')
});
}

Expand Down
10 changes: 0 additions & 10 deletions skillmap/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class AppImpl extends React.Component<AppProps, AppState> {
// TODO: include the pxt webconfig so that we can get the commitcdnurl (and not always pass live=true)
const baseUrl = "";
const targetId = pxt.appTarget.id;
const pxtBranch = pxt.appTarget.versions.pxtCrowdinBranch;
const targetBranch = pxt.appTarget.versions.targetCrowdinBranch;

const langLowerCase = useLang?.toLocaleLowerCase();
const localDevServe = pxt.BrowserUtils.isLocalHostDev()
Expand All @@ -175,8 +173,6 @@ class AppImpl extends React.Component<AppProps, AppState> {
targetId: targetId,
baseUrl: baseUrl,
code: useLang!,
pxtBranch: pxtBranch!,
targetBranch: targetBranch!,
force: force,
});

Expand Down Expand Up @@ -544,17 +540,13 @@ interface LocalizationUpdateOptions {
targetId: string;
baseUrl: string;
code: string;
pxtBranch: string;
targetBranch: string;
force?: boolean;
}

async function updateLocalizationAsync(opts: LocalizationUpdateOptions): Promise<void> {
const {
targetId,
baseUrl,
pxtBranch,
targetBranch,
force,
} = opts;
let { code } = opts;
Expand All @@ -563,8 +555,6 @@ async function updateLocalizationAsync(opts: LocalizationUpdateOptions): Promise
targetId,
baseUrl,
code,
pxtBranch,
targetBranch,
pxt.Util.liveLocalizationEnabled(),
ts.pxtc.Util.TranslationsKind.SkillMap
);
Expand Down
7 changes: 1 addition & 6 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5979,14 +5979,10 @@ document.addEventListener("DOMContentLoaded", async () => {
}
const targetId = pxt.appTarget.id;
const baseUrl = config.commitCdnUrl;
const pxtBranch = pxt.appTarget.versions.pxtCrowdinBranch;
const targetBranch = pxt.appTarget.versions.targetCrowdinBranch;
return Util.updateLocalizationAsync({
targetId: targetId,
baseUrl: baseUrl,
code: useLang,
pxtBranch: pxtBranch,
targetBranch: targetBranch,
force: force,
}).then(() => {
if (pxt.Util.isLocaleEnabled(useLang)) {
Expand All @@ -5999,8 +5995,7 @@ document.addEventListener("DOMContentLoaded", async () => {
// Download sim translations and save them in the sim
// don't wait!
Util.downloadTranslationsAsync(
targetId, baseUrl, useLang,
pxtBranch, targetBranch, pxt.Util.liveLocalizationEnabled(), Util.TranslationsKind.Sim)
targetId, baseUrl, useLang, pxt.Util.liveLocalizationEnabled(), Util.TranslationsKind.Sim)
.then(simStrings => simStrings && simulator.setTranslations(simStrings))
});
})
Expand Down