-
Notifications
You must be signed in to change notification settings - Fork 199
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
Write a script that does a best guess at calculating locale translation percentages #550
Comments
I'd actually prefer to make this part of |
@flodolo is there any kind of Pontoon API we could query to get the translation % for a project per locale? |
This API call should give you the data you need. The query looks like this: query {
project(slug: "firefox-monitor-website") {
name
localizations {
locale {
code
},
approvedStrings,
stringsWithWarnings,
totalStrings,
}
}
} Completion is calculated as You can also have a look at the blog post to learn more about the API. |
Awesome, I was looking for an excuse to poke around w/ graphql. This is about as close as I got. Oddly, I'm not seeing our default locale ("en") in the results: const got = require("got");
const PROJECT_SLUG = "firefox-monitor-website";
const query = `{project(slug:"${PROJECT_SLUG}"){name,localizations{locale{code,name}totalStrings,approvedStrings,stringsWithWarnings,missingStrings}}}`;
async function main() {
const {body} = await got("https://pontoon.mozilla.org/graphql", {json: true, query: `query=${query}`});
const localizations = body.data.project.localizations
.map(locale => {
locale.progress = (1 - (locale.missingStrings / locale.totalStrings)) * 100;
return locale;
})
.filter(locale => locale.progress > 0)
.sort((localeA, localeB) => localeB.progress - localeA.progress);
localizations.forEach(locale => console.log(`${locale.locale.code} \t => ${Math.round(locale.progress)}%`));
}
main()
.catch(err => console.error(err)); $ node graphql-test.js
zh-CN => 100%
de => 100%
cy => 100%
zh-TW => 100%
en-CA => 100%
cs => 95%
fr => 58%
sl => 54%
pt-PT => 41%
id => 38%
es-AR => 32%
az => 25%
sv-SE => 21%
sk => 14%
kab => 12%
es-CL => 9%
ur => 9%
it => 7%
ru => 7%
es-MX => 6%
ja => 3% UPDATE: Or this one, which combines the const got = require("got");
async function main(slug) {
const query = {query: `{project(slug:"${slug}"){name,localizations{locale{code,name}totalStrings,approvedStrings,stringsWithWarnings,missingStrings}}}`};
const {body} = await got("https://pontoon.mozilla.org/graphql", {json: true, query});
// TODO: Add a couple more guards around blindly hoping "body.data.project.localizations"
// is a thing.
const localizations = body.data.project.localizations
.reduce((arr, locale) => {
locale.progress = (locale.approvedStrings + locale.stringsWithWarnings) / locale.totalStrings * 100;
if (locale.progress > 0) {
arr.push(locale);
}
return arr;
}, [])
.sort((localeA, localeB) => localeB.progress - localeA.progress);
localizations.unshift({locale: {code: "en"}, progress: 100});
localizations.forEach(locale => console.log(`${locale.locale.code} \t => ${Math.round(locale.progress)}%`));
}
main("firefox-monitor-website")
.catch(err => console.error(err)); UPDATE: Pretty boring, but I pushed a version of this to my GitHub repo as a Node module (but haven't published to npm): https://github.com/pdehaan/pontoonql |
Pulling this out of l10n launch milestone. We're going to launch with a manually-configured list of supported locales in an environment variable. (See #563) |
Closing since we've redesigned the site and functionality since this was created. If you feel that this is still needed, please let me know. |
Not sure if there's much value in a local script that would calculate translation percentages, since we can get that information from https://pontoon.mozilla.org/projects/firefox-monitor-website/ but it may be useful if we want to try scripting which locales to say are "production ready".
I took a stab at it, and the results seem to be similar to Pontoon site (give or take some minor rounding variations).
Output:
$ node l10n-lint.js total "en" strings: 261 - en = 100% - en-CA = 100% - de = 100% - zh-TW = 85% - sl = 47% - pt-PT = 42% - cy = 22% - sv-SE = 18% - fr = 14% - zh-CN = 10% - it = 3% - es-MX = 2%
UPDATE: Updated the code above to allow for an ominous
--threshold
(or-t
) argument which lets you set a minimum translation %:$ node l10n-lint.js -t 85 total "en" strings: 261 - de = 100% - en = 100% - en-CA = 100% - zh-TW = 85%
UPDATE: Refactored and added a couple more CLI flags. Now you can specify
--json
which will return an array of locales (which may play a bit nicer w/ l10n.toml):The text was updated successfully, but these errors were encountered: