mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1024757 - Translation FHR should report missed opportunities due to the detected language not being part of the list of supported languages. r=mdeboer
This commit is contained in:
parent
09894ec2b1
commit
9e9e57331a
@ -48,9 +48,16 @@ this.Translation = {
|
||||
|
||||
documentStateReceived: function(aBrowser, aData) {
|
||||
if (aData.state == this.STATE_OFFER) {
|
||||
if (this.supportedSourceLanguages.indexOf(aData.detectedLanguage) == -1 ||
|
||||
aData.detectedLanguage == this.defaultTargetLanguage)
|
||||
if (aData.detectedLanguage == this.defaultTargetLanguage) {
|
||||
// Detected language is the same as the user's locale.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.supportedSourceLanguages.indexOf(aData.detectedLanguage) == -1) {
|
||||
// Detected language is not part of the supported languages.
|
||||
TranslationHealthReport.recordMissedTranslationOpportunity(aData.detectedLanguage);
|
||||
return;
|
||||
}
|
||||
|
||||
TranslationHealthReport.recordTranslationOpportunity(aData.detectedLanguage);
|
||||
}
|
||||
@ -242,6 +249,17 @@ let TranslationHealthReport = {
|
||||
this._withProvider(provider => provider.recordTranslationOpportunity(language));
|
||||
},
|
||||
|
||||
/**
|
||||
* Record a missed translation opportunity in the health report.
|
||||
* A missed opportunity is when the language detected is not part
|
||||
* of the supported languages.
|
||||
* @param language
|
||||
* The language of the page.
|
||||
*/
|
||||
recordMissedTranslationOpportunity: function (language) {
|
||||
this._withProvider(provider => provider.recordMissedTranslationOpportunity(language));
|
||||
},
|
||||
|
||||
/**
|
||||
* Record a translation in the health report.
|
||||
* @param langFrom
|
||||
@ -321,9 +339,11 @@ TranslationMeasurement1.prototype = Object.freeze({
|
||||
|
||||
fields: {
|
||||
translationOpportunityCount: DAILY_COUNTER_FIELD,
|
||||
missedTranslationOpportunityCount: DAILY_COUNTER_FIELD,
|
||||
pageTranslatedCount: DAILY_COUNTER_FIELD,
|
||||
charactersTranslatedCount: DAILY_COUNTER_FIELD,
|
||||
translationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
|
||||
missedTranslationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
|
||||
pageTranslatedCountsByLanguage: DAILY_LAST_TEXT_FIELD,
|
||||
detectedLanguageChangedBefore: DAILY_COUNTER_FIELD,
|
||||
detectedLanguageChangedAfter: DAILY_COUNTER_FIELD,
|
||||
@ -368,6 +388,7 @@ TranslationMeasurement1.prototype = Object.freeze({
|
||||
// Special case the serialization of these fields so that
|
||||
// they are sent as objects, not stringified objects.
|
||||
_parseInPlace(result, "translationOpportunityCountsByLanguage");
|
||||
_parseInPlace(result, "missedTranslationOpportunityCountsByLanguage");
|
||||
_parseInPlace(result, "pageTranslatedCountsByLanguage");
|
||||
|
||||
return result;
|
||||
@ -407,6 +428,25 @@ TranslationProvider.prototype = Object.freeze({
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
recordMissedTranslationOpportunity: function (language, date=new Date()) {
|
||||
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
|
||||
TranslationMeasurement1.prototype.version);
|
||||
|
||||
return this._enqueueTelemetryStorageTask(function* recordTask() {
|
||||
yield m.incrementDailyCounter("missedTranslationOpportunityCount", date);
|
||||
|
||||
let langCounts = yield m._getDailyLastTextFieldAsJSON(
|
||||
"missedTranslationOpportunityCountsByLanguage", date);
|
||||
|
||||
langCounts[language] = (langCounts[language] || 0) + 1;
|
||||
langCounts = JSON.stringify(langCounts);
|
||||
|
||||
yield m.setDailyLastText("missedTranslationOpportunityCountsByLanguage",
|
||||
langCounts, date);
|
||||
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
recordTranslation: function (langFrom, langTo, numCharacters, date=new Date()) {
|
||||
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
|
||||
TranslationMeasurement1.prototype.version);
|
||||
|
@ -69,21 +69,47 @@ add_task(function* test_translation_opportunity() {
|
||||
let countsByLanguage = JSON.parse(day.get("translationOpportunityCountsByLanguage"));
|
||||
Assert.equal(countsByLanguage["fr"], 1);
|
||||
|
||||
// Record a missed opportunity.
|
||||
yield provider.recordMissedTranslationOpportunity("it", now);
|
||||
|
||||
values = yield m.getValues();
|
||||
day = values.days.getDay(now);
|
||||
Assert.equal(values.days.size, 1);
|
||||
Assert.ok(values.days.hasDay(now));
|
||||
Assert.ok(day.has("missedTranslationOpportunityCount"));
|
||||
Assert.equal(day.get("missedTranslationOpportunityCount"), 1);
|
||||
|
||||
Assert.ok(day.has("missedTranslationOpportunityCountsByLanguage"));
|
||||
let missedCountsByLanguage = JSON.parse(day.get("missedTranslationOpportunityCountsByLanguage"));
|
||||
Assert.equal(missedCountsByLanguage["it"], 1);
|
||||
|
||||
// Record more opportunities.
|
||||
yield provider.recordTranslationOpportunity("fr", now);
|
||||
yield provider.recordTranslationOpportunity("fr", now);
|
||||
yield provider.recordTranslationOpportunity("es", now);
|
||||
|
||||
yield provider.recordMissedTranslationOpportunity("it", now);
|
||||
yield provider.recordMissedTranslationOpportunity("cs", now);
|
||||
yield provider.recordMissedTranslationOpportunity("fi", now);
|
||||
|
||||
values = yield m.getValues();
|
||||
let day = values.days.getDay(now);
|
||||
day = values.days.getDay(now);
|
||||
Assert.ok(day.has("translationOpportunityCount"));
|
||||
Assert.equal(day.get("translationOpportunityCount"), 4);
|
||||
Assert.ok(day.has("missedTranslationOpportunityCount"));
|
||||
Assert.equal(day.get("missedTranslationOpportunityCount"), 4);
|
||||
|
||||
Assert.ok(day.has("translationOpportunityCountsByLanguage"));
|
||||
countsByLanguage = JSON.parse(day.get("translationOpportunityCountsByLanguage"));
|
||||
Assert.equal(countsByLanguage["fr"], 3);
|
||||
Assert.equal(countsByLanguage["es"], 1);
|
||||
|
||||
Assert.ok(day.has("missedTranslationOpportunityCountsByLanguage"));
|
||||
missedCountsByLanguage = JSON.parse(day.get("missedTranslationOpportunityCountsByLanguage"));
|
||||
Assert.equal(missedCountsByLanguage["it"], 2);
|
||||
Assert.equal(missedCountsByLanguage["cs"], 1);
|
||||
Assert.equal(missedCountsByLanguage["fi"], 1);
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
@ -1542,6 +1542,10 @@ Daily counts are reported in the following properties:
|
||||
|
||||
translationOpportunityCount
|
||||
Integer count of the number of opportunities there were to translate a page.
|
||||
missedTranslationOpportunityCount
|
||||
Integer count of the number of missed opportunities there were to translate a page.
|
||||
A missed opportunity is when the page language is not supported by the translation
|
||||
provider.
|
||||
pageTranslatedCount
|
||||
Integer count of the number of pages translated.
|
||||
charactersTranslatedCount
|
||||
@ -1559,6 +1563,9 @@ properties:
|
||||
translationOpportunityCountsByLanguage
|
||||
A mapping from language to count of opportunities to translate that
|
||||
language.
|
||||
missedTranslationOpportunityCountsByLanguage
|
||||
A mapping from language to count of missed opportunities to translate that
|
||||
language.
|
||||
pageTranslatedCountsByLanguage
|
||||
A mapping from language to the counts of pages translated from that
|
||||
language. Each language entry will be an object containing a "total" member
|
||||
|
Loading…
Reference in New Issue
Block a user