Clarify metric values for result events
This commit is contained in:
@@ -713,14 +713,42 @@ export type Events = {
|
||||
textLength: number
|
||||
}
|
||||
'translate:result': {
|
||||
method: 'on-device' | 'fallback-alert'
|
||||
success: boolean
|
||||
os: Platform['OS']
|
||||
sourceSelection: 'automatic' | 'manual'
|
||||
sourceLanguage: string | null
|
||||
targetLanguage: string
|
||||
|
||||
/* Only relevant to posts */
|
||||
postLanguages?: string[]
|
||||
/**
|
||||
* The languages the content might be in, such as the user-supplied
|
||||
* language codes on posts. Currently only available on posts.
|
||||
*/
|
||||
possibleSourceLanguages: string[] | undefined
|
||||
/**
|
||||
* The language we expected the content to be in. This could be based on
|
||||
* user selection or on our confidence in the detected language. This is
|
||||
* nullable because we may not always have an expected source language.
|
||||
*/
|
||||
expectedSourceLanguage: string | null
|
||||
/**
|
||||
* This is the user's configured primary language, which is always defined.
|
||||
*/
|
||||
expectedTargetLanguage: string
|
||||
/**
|
||||
* The language the translation result was actually in. This is nullable
|
||||
* because the translation could have failed, in which case we won't have a
|
||||
* result source language.
|
||||
*/
|
||||
resultSourceLanguage: string | null
|
||||
/**
|
||||
* The language the translation result was translated into. This should be
|
||||
* the same as `expectedTargetLanguage`, but we include it for completeness
|
||||
* and in case there are any edge cases where they differ. This is nullable
|
||||
* because if the translation failed, we won't have a result target
|
||||
* language.
|
||||
*/
|
||||
resultTargetLanguage: string | null
|
||||
/**
|
||||
* The length of the text being translated. We assume shorter texts are
|
||||
* more likely to have inaccurate translations.
|
||||
*/
|
||||
textLength: number
|
||||
}
|
||||
'translate:override': {
|
||||
os: Platform['OS']
|
||||
|
||||
@@ -408,7 +408,6 @@ function TranslationLanguageSelect({
|
||||
text: postText,
|
||||
targetLangCode: langPrefs.primaryLanguage,
|
||||
sourceLangCode,
|
||||
sourceSelection: 'manual',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -212,13 +212,12 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
|
||||
key,
|
||||
text,
|
||||
targetLangCode,
|
||||
sourceLangCode,
|
||||
sourceSelection = 'automatic',
|
||||
sourceLangCode: expectedSourceLanguage,
|
||||
postLangCodes,
|
||||
...options
|
||||
}) => {
|
||||
if (options?.forceGoogleTranslate || !HAS_ON_DEVICE_TRANSLATION) {
|
||||
await googleTranslate(text, targetLangCode, sourceLangCode)
|
||||
await googleTranslate(text, targetLangCode, expectedSourceLanguage)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -233,15 +232,17 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
|
||||
const result = await attemptTranslation(
|
||||
text,
|
||||
targetLangCode,
|
||||
sourceLangCode,
|
||||
expectedSourceLanguage,
|
||||
)
|
||||
ax.metric('translate:result', {
|
||||
method: 'on-device',
|
||||
success: true,
|
||||
os: Platform.OS,
|
||||
sourceSelection,
|
||||
sourceLanguage: result.sourceLanguage,
|
||||
targetLanguage: result.targetLanguage,
|
||||
postLanguages: postLangCodes,
|
||||
possibleSourceLanguages: postLangCodes,
|
||||
expectedSourceLanguage: expectedSourceLanguage ?? null,
|
||||
expectedTargetLanguage: targetLangCode,
|
||||
resultSourceLanguage: result.sourceLanguage,
|
||||
resultTargetLanguage: result.targetLanguage,
|
||||
textLength: text.length,
|
||||
})
|
||||
if (!IS_ANDROID) {
|
||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||
@@ -261,12 +262,14 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
|
||||
// On-device translation failed (language pack missing or user
|
||||
// dismissed the download prompt).
|
||||
ax.metric('translate:result', {
|
||||
method: 'fallback-alert',
|
||||
success: false,
|
||||
os: Platform.OS,
|
||||
sourceSelection,
|
||||
sourceLanguage: sourceLangCode ?? null,
|
||||
targetLanguage: targetLangCode,
|
||||
postLanguages: postLangCodes,
|
||||
possibleSourceLanguages: postLangCodes,
|
||||
expectedSourceLanguage: expectedSourceLanguage ?? null,
|
||||
expectedTargetLanguage: targetLangCode,
|
||||
resultSourceLanguage: null,
|
||||
resultTargetLanguage: null,
|
||||
textLength: text.length,
|
||||
})
|
||||
let errorMessage = l`Device failed to translate :(`
|
||||
if (!IS_ANDROID) {
|
||||
|
||||
@@ -24,13 +24,12 @@ export type TranslationFunctionParams = {
|
||||
*/
|
||||
targetLangCode: string
|
||||
/**
|
||||
* The source language of the text. Will auto-detect if not provided.
|
||||
* We auto-detect the source language by default, but the user has the option
|
||||
* to specify a source language if they want to. If this value is present, it
|
||||
* means the user selected a source language, or we were certain of the
|
||||
* source language and want to specify it explicitly.
|
||||
*/
|
||||
sourceLangCode?: string
|
||||
/**
|
||||
* Whether we auto-detected the language or it was selected manually. Defaults to 'automatic'.
|
||||
*/
|
||||
sourceSelection?: 'automatic' | 'manual'
|
||||
}
|
||||
|
||||
export type TranslationOptions = {
|
||||
|
||||
Reference in New Issue
Block a user