Clarify metric values for result events
This commit is contained in:
@@ -713,14 +713,42 @@ export type Events = {
|
|||||||
textLength: number
|
textLength: number
|
||||||
}
|
}
|
||||||
'translate:result': {
|
'translate:result': {
|
||||||
method: 'on-device' | 'fallback-alert'
|
success: boolean
|
||||||
os: Platform['OS']
|
os: Platform['OS']
|
||||||
sourceSelection: 'automatic' | 'manual'
|
/**
|
||||||
sourceLanguage: string | null
|
* The languages the content might be in, such as the user-supplied
|
||||||
targetLanguage: string
|
* language codes on posts. Currently only available on posts.
|
||||||
|
*/
|
||||||
/* Only relevant to posts */
|
possibleSourceLanguages: string[] | undefined
|
||||||
postLanguages?: string[]
|
/**
|
||||||
|
* 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': {
|
'translate:override': {
|
||||||
os: Platform['OS']
|
os: Platform['OS']
|
||||||
|
|||||||
@@ -408,7 +408,6 @@ function TranslationLanguageSelect({
|
|||||||
text: postText,
|
text: postText,
|
||||||
targetLangCode: langPrefs.primaryLanguage,
|
targetLangCode: langPrefs.primaryLanguage,
|
||||||
sourceLangCode,
|
sourceLangCode,
|
||||||
sourceSelection: 'manual',
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,13 +212,12 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
|
|||||||
key,
|
key,
|
||||||
text,
|
text,
|
||||||
targetLangCode,
|
targetLangCode,
|
||||||
sourceLangCode,
|
sourceLangCode: expectedSourceLanguage,
|
||||||
sourceSelection = 'automatic',
|
|
||||||
postLangCodes,
|
postLangCodes,
|
||||||
...options
|
...options
|
||||||
}) => {
|
}) => {
|
||||||
if (options?.forceGoogleTranslate || !HAS_ON_DEVICE_TRANSLATION) {
|
if (options?.forceGoogleTranslate || !HAS_ON_DEVICE_TRANSLATION) {
|
||||||
await googleTranslate(text, targetLangCode, sourceLangCode)
|
await googleTranslate(text, targetLangCode, expectedSourceLanguage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,15 +232,17 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
|
|||||||
const result = await attemptTranslation(
|
const result = await attemptTranslation(
|
||||||
text,
|
text,
|
||||||
targetLangCode,
|
targetLangCode,
|
||||||
sourceLangCode,
|
expectedSourceLanguage,
|
||||||
)
|
)
|
||||||
ax.metric('translate:result', {
|
ax.metric('translate:result', {
|
||||||
method: 'on-device',
|
success: true,
|
||||||
os: Platform.OS,
|
os: Platform.OS,
|
||||||
sourceSelection,
|
possibleSourceLanguages: postLangCodes,
|
||||||
sourceLanguage: result.sourceLanguage,
|
expectedSourceLanguage: expectedSourceLanguage ?? null,
|
||||||
targetLanguage: result.targetLanguage,
|
expectedTargetLanguage: targetLangCode,
|
||||||
postLanguages: postLangCodes,
|
resultSourceLanguage: result.sourceLanguage,
|
||||||
|
resultTargetLanguage: result.targetLanguage,
|
||||||
|
textLength: text.length,
|
||||||
})
|
})
|
||||||
if (!IS_ANDROID) {
|
if (!IS_ANDROID) {
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
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
|
// On-device translation failed (language pack missing or user
|
||||||
// dismissed the download prompt).
|
// dismissed the download prompt).
|
||||||
ax.metric('translate:result', {
|
ax.metric('translate:result', {
|
||||||
method: 'fallback-alert',
|
success: false,
|
||||||
os: Platform.OS,
|
os: Platform.OS,
|
||||||
sourceSelection,
|
possibleSourceLanguages: postLangCodes,
|
||||||
sourceLanguage: sourceLangCode ?? null,
|
expectedSourceLanguage: expectedSourceLanguage ?? null,
|
||||||
targetLanguage: targetLangCode,
|
expectedTargetLanguage: targetLangCode,
|
||||||
postLanguages: postLangCodes,
|
resultSourceLanguage: null,
|
||||||
|
resultTargetLanguage: null,
|
||||||
|
textLength: text.length,
|
||||||
})
|
})
|
||||||
let errorMessage = l`Device failed to translate :(`
|
let errorMessage = l`Device failed to translate :(`
|
||||||
if (!IS_ANDROID) {
|
if (!IS_ANDROID) {
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ export type TranslationFunctionParams = {
|
|||||||
*/
|
*/
|
||||||
targetLangCode: string
|
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
|
sourceLangCode?: string
|
||||||
/**
|
|
||||||
* Whether we auto-detected the language or it was selected manually. Defaults to 'automatic'.
|
|
||||||
*/
|
|
||||||
sourceSelection?: 'automatic' | 'manual'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TranslationOptions = {
|
export type TranslationOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user