-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Added count param to phrase param and return plural form accordingly #48229
Changes from 1 commit
736b250
9d42d55
e830bb5
09f51d4
a237886
d0bf65b
41f0334
078a5ad
b70f5e4
f31c7f2
af67cd0
eab923d
5d1a70c
41a3199
8ebf751
273c8e1
d63aa0d
4b7eb6d
57d8b7f
83481bf
554611c
7c24bb4
d3028b6
100feae
87fd61d
101fd03
90af317
362c264
8f58c9e
04c8f76
bd485f9
5d73e02
0002662
4e0d494
2b84c98
2175302
d7f49e5
090af99
e278f17
be492c0
94d170b
ffcd48e
480bdda
1ebfb54
27b7056
7638a4c
12b3b41
a36a304
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- 9.1.6-0
- 9.1.5-5
- 9.1.5-4
- 9.1.5-3
- 9.1.5-2
- 9.1.5-1
- 9.1.5-0
- 9.1.4-4
- 9.1.4-3
- 9.1.4-2
- 9.1.4-1
- 9.1.4-0
- 9.1.3-4
- 9.1.3-3
- 9.1.3-2
- 9.1.3-1
- 9.1.3-0
- 9.1.2-1
- 9.1.2-0
- 9.1.1-6
- 9.1.1-4
- 9.1.1-3
- 9.1.1-2
- 9.1.1-1
- 9.1.1-0
- 9.1.0-2
- 9.1.0-1
- 9.1.0-0
- 9.0.99-2
- 9.0.99-1
- 9.0.99-0
- 9.0.98-8
- 9.0.98-7
- 9.0.98-6
- 9.0.98-5
- 9.0.98-4
- 9.0.98-3
- 9.0.98-2
- 9.0.98-1
- 9.0.98-0
- 9.0.97-1
- 9.0.97-0
- 9.0.96-1
- 9.0.96-0
- 9.0.95-6
- 9.0.95-5
- 9.0.95-3
- 9.0.95-1
- 9.0.95-0
- 9.0.94-25
- 9.0.94-24
- 9.0.94-23
- 9.0.94-17
- 9.0.94-16
- 9.0.94-10
- 9.0.94-8
- 9.0.94-7
- 9.0.94-5
- 9.0.94-4
- 9.0.94-2
- 9.0.94-1
- 9.0.94-0
- 9.0.93-3
- 9.0.93-2
- 9.0.93-1
- 9.0.93-0
- 9.0.92-6
- 9.0.92-5
- 9.0.92-4
- 9.0.92-2
- 9.0.92-1
- 9.0.92-0
- 9.0.91-2
- 9.0.91-1
- 9.0.91-0
- 9.0.90-6
- 9.0.90-5
- 9.0.90-3
- 9.0.90-2
- 9.0.90-1
- 9.0.90-0
- 9.0.89-8
- 9.0.89-7
- 9.0.89-6
- 9.0.89-5
- 9.0.89-4
- 9.0.89-3
- 9.0.89-2
- 9.0.89-1
- 9.0.89-0
- 9.0.88-7
- 9.0.88-6
- 9.0.88-5
- 9.0.88-4
- 9.0.88-3
- 9.0.88-2
- 9.0.88-1
- 9.0.88-0
- 9.0.87-3
- 9.0.87-2
- 9.0.87-1
- 9.0.87-0
- 9.0.86-3
- 9.0.86-2
- 9.0.86-1
- 9.0.86-0
- 9.0.85-4
- 9.0.85-3
- 9.0.85-1
- 9.0.85-0
- 9.0.84-7
- 9.0.84-6
- 9.0.84-5
- 9.0.84-4
- 9.0.84-3
- 9.0.84-2
- 9.0.84-1
- 9.0.84-0
- 9.0.83-5
- 9.0.83-4
- 9.0.83-3
- 9.0.83-2
- 9.0.83-1
- 9.0.83-0
- 9.0.82-12
- 9.0.82-11
- 9.0.82-9
- 9.0.82-8
- 9.0.82-7
- 9.0.82-6
- 9.0.82-5
- 9.0.82-4
- 9.0.82-3
- 9.0.82-2
- 9.0.82-1
- 9.0.82-0
- 9.0.81-6
- 9.0.81-5
- 9.0.81-4
- 9.0.81-3
- 9.0.81-2
- 9.0.81-1
- 9.0.81-0
- 9.0.80-6
- 9.0.80-4
- 9.0.80-3
- 9.0.80-2
- 9.0.80-1
- 9.0.79-5
- 9.0.79-4
- 9.0.79-3
- 9.0.79-2
- 9.0.79-1
- 9.0.79-0
- 9.0.78-6
- 9.0.78-5
- 9.0.78-4
- 9.0.78-3
- 9.0.78-2
- 9.0.78-1
- 9.0.78-0
- 9.0.77-6
- 9.0.77-5
- 9.0.77-4
- 9.0.77-3
- 9.0.77-2
- 9.0.77-1
- 9.0.77-0
- 9.0.76-12
- 9.0.76-11
- 9.0.76-10
- 9.0.76-9
- 9.0.76-8
- 9.0.76-7
- 9.0.76-6
- 9.0.76-3
- 9.0.76-2
- 9.0.76-1
- 9.0.76-0
- 9.0.75-6
- 9.0.75-5
- 9.0.75-4
- 9.0.75-3
- 9.0.75-2
- 9.0.75-1
- 9.0.75-0
- 9.0.74-8
- 9.0.74-7
- 9.0.74-6
- 9.0.74-5
- 9.0.74-4
- 9.0.74-3
- 9.0.74-2
- 9.0.74-0
- 9.0.73-8
- 9.0.73-7
- 9.0.73-6
- 9.0.73-5
- 9.0.73-4
- 9.0.73-3
- 9.0.73-1
- 9.0.73-0
- 9.0.72-1
- 9.0.72-0
- 9.0.71-2
- 9.0.71-1
- 9.0.71-0
- 9.0.70-9
- 9.0.70-8
- 9.0.70-6
- 9.0.70-3
- 9.0.70-2
- 9.0.70-1
- 9.0.70-0
- 9.0.69-4
- 9.0.69-3
- 9.0.69-2
- 9.0.69-1
- 9.0.69-0
- 9.0.68-7
- 9.0.68-6
- 9.0.68-5
- 9.0.68-4
- 9.0.68-3
- 9.0.68-2
- 9.0.68-1
- 9.0.68-0
- 9.0.67-9
- 9.0.67-8
- 9.0.67-7
- 9.0.67-6
- 9.0.67-5
- 9.0.67-4
- 9.0.67-3
- 9.0.67-2
- 9.0.67-1
- 9.0.67-0
- 9.0.66-8
- 9.0.66-7
- 9.0.66-6
- 9.0.66-5
- 9.0.66-4
- 9.0.66-3
- 9.0.66-2
- 9.0.66-1
- 9.0.66-0
- 9.0.65-5
- 9.0.65-4
- 9.0.65-3
- 9.0.65-2
- 9.0.65-1
- 9.0.65-0
- 9.0.64-4
- 9.0.64-3
- 9.0.64-2
- 9.0.64-1
- 9.0.64-0
- 9.0.63-3
- 9.0.63-2
- 9.0.63-1
- 9.0.63-0
- 9.0.62-4
- 9.0.62-3
- 9.0.62-2
- 9.0.62-1
- 9.0.62-0
- 9.0.61-3
- 9.0.61-2
- 9.0.61-1
- 9.0.61-0
- 9.0.60-3
- 9.0.60-2
- 9.0.60-1
- 9.0.60-0
- 9.0.59-3
- 9.0.59-2
- 9.0.59-1
- 9.0.59-0
- 9.0.58-2
- 9.0.58-1
- 9.0.58-0
- 9.0.57-10
- 9.0.57-9
- 9.0.57-8
- 9.0.57-7
- 9.0.57-4
- 9.0.57-3
- 9.0.57-2
- 9.0.57-1
- 9.0.57-0
- 9.0.56-9
- 9.0.56-8
- 9.0.56-7
- 9.0.56-6
- 9.0.56-5
- 9.0.56-4
- 9.0.56-3
- 9.0.56-2
- 9.0.56-0
- 9.0.55-10
- 9.0.55-9
- 9.0.55-8
- 9.0.55-7
- 9.0.55-6
- 9.0.55-5
- 9.0.55-4
- 9.0.55-3
- 9.0.55-2
- 9.0.55-1
- 9.0.55-0
- 9.0.54-11
- 9.0.54-10
- 9.0.54-9
- 9.0.54-8
- 9.0.54-7
- 9.0.54-6
- 9.0.54-2
- 9.0.54-1
- 9.0.54-0
- 9.0.53-1
- 9.0.53-0
- 9.0.52-5
- 9.0.52-4
- 9.0.52-3
- 9.0.52-2
- 9.0.52-1
- 9.0.52-0
- 9.0.51-4
- 9.0.51-3
- 9.0.51-2
- 9.0.51-1
- 9.0.51-0
- 9.0.50-8
- 9.0.50-7
- 9.0.50-6
- 9.0.50-5
- 9.0.50-4
- 9.0.50-3
- 9.0.50-2
- 9.0.50-1
- 9.0.50-0
- 9.0.49-2
- 9.0.49-1
- 9.0.49-0
- 9.0.48-2
- 9.0.48-1
- 9.0.48-0
- 9.0.47-4
- 9.0.47-3
- 9.0.47-2
- 9.0.47-1
- 9.0.47-0
- 9.0.46-5
- 9.0.46-4
- 9.0.46-3
- 9.0.46-2
- 9.0.46-1
- 9.0.46-0
- 9.0.45-4
- 9.0.45-3
- 9.0.45-2
- 9.0.45-1
- 9.0.45-0
- 9.0.44-12
- 9.0.44-11
- 9.0.44-10
- 9.0.44-9
- 9.0.44-8
- 9.0.44-7
- 9.0.44-6
- 9.0.44-5
- 9.0.44-4
- 9.0.44-3
- 9.0.44-2
- 9.0.44-1
- 9.0.44-0
- 9.0.43-6
- 9.0.43-5
- 9.0.43-4
- 9.0.43-3
- 9.0.43-2
- 9.0.43-1
- 9.0.43-0
- 9.0.42-3
- 9.0.42-2
- 9.0.42-1
- 9.0.42-0
- 9.0.41-10
- 9.0.41-9
- 9.0.41-8
- 9.0.41-7
- 9.0.41-6
- 9.0.41-5
- 9.0.41-4
- 9.0.41-3
- 9.0.41-2
- 9.0.41-1
- 9.0.41-0
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3711,7 +3711,10 @@ const translations = { | |
rate: 'Tasa', | ||
addRate: 'Agregar tasa', | ||
trackTax: 'Impuesto de seguimiento', | ||
deleteRates: ({count}: DistanceRateOperationsParams) => `Eliminar ${Str.pluralize('tasa', 'tasas', count)}`, | ||
deleteRates: () => ({ | ||
one: 'Eliminar tasa', | ||
other: () => `Eliminar tasas`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
}), | ||
enableRates: ({count}: DistanceRateOperationsParams) => `Activar ${Str.pluralize('tasa', 'tasas', count)}`, | ||
disableRates: ({count}: DistanceRateOperationsParams) => `Desactivar ${Str.pluralize('tasa', 'tasas', count)}`, | ||
enableRate: 'Activar tasa', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,37 +80,35 @@ const translationCache = new Map<ValueOf<typeof CONST.LOCALES>, Map<TranslationP | |
* phrase and stores the translated value in the cache and returns | ||
* the translated value. | ||
*/ | ||
function getTranslatedPhrase<TPath extends TranslationPaths>( | ||
function getTranslatedPhrase<TKey extends TranslationPaths>( | ||
language: 'en' | 'es' | 'es-ES', | ||
path: TPath, | ||
phraseKey: TKey, | ||
fallbackLanguage: 'en' | 'es' | null, | ||
...parameters: TranslationParameters<TPath> | ||
...parameters: TranslationParameters<TKey> | ||
): string | null { | ||
// Get the cache for the above locale | ||
const cacheForLocale = translationCache.get(language); | ||
|
||
// Directly access and assign the translated value from the cache, instead of | ||
// going through map.has() and map.get() to avoid multiple lookups. | ||
const valueFromCache = cacheForLocale?.get(path); | ||
const valueFromCache = cacheForLocale?.get(phraseKey); | ||
|
||
// If the phrase is already translated, return the translated value | ||
if (valueFromCache) { | ||
return valueFromCache; | ||
} | ||
|
||
const translatedPhrase = translations?.[language]?.[path]; | ||
const translatedPhrase = translations?.[language]?.[phraseKey]; | ||
|
||
if (translatedPhrase) { | ||
if (typeof translatedPhrase === 'function') { | ||
/** | ||
* | ||
* is Plain object is for checking if the phraseTranslated output | ||
* is an object then further check if it include the count param or not | ||
* OR before checking the plain object output, we can check if we have the count | ||
* param in parameters | ||
* | ||
* If the result of `translatedPhrase` is an object, check if it contains the 'count' property | ||
* to handle pluralization logic. | ||
* Alternatively, before evaluating the translated result, we can check if the 'count' parameter | ||
* exists in the passed parameters. | ||
*/ | ||
const translateFunction = translatedPhrase as unknown as (...parameters: TranslationParameters<TPath>) => string | PluralForm; | ||
const translateFunction = translatedPhrase as unknown as (...parameters: TranslationParameters<TKey>) => string | PluralForm; | ||
const translateResult = translateFunction(...parameters); | ||
|
||
if (typeof translateResult === 'string') { | ||
|
@@ -121,7 +119,7 @@ function getTranslatedPhrase<TPath extends TranslationPaths>( | |
if (phraseObject && typeof phraseObject === 'object' && 'count' in phraseObject && typeof phraseObject.count === 'number') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need some additional clarification to prevent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we change the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why?
Which we could remove if we added it as an optional param, no? |
||
const pluralRule = new Intl.PluralRules(language).select(phraseObject.count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See here |
||
|
||
const pluralResult = pluralRule in translateResult && translateResult[pluralRule]; | ||
const pluralResult = translateResult[pluralRule]; | ||
if (pluralResult) { | ||
if (typeof pluralResult === 'string') { | ||
return pluralResult; | ||
|
@@ -133,11 +131,11 @@ function getTranslatedPhrase<TPath extends TranslationPaths>( | |
return translateResult.other(phraseObject.count); | ||
} | ||
|
||
throw new Error(`Invalid plural form for '${path}'`); | ||
throw new Error(`Invalid plural form for '${phraseKey}'`); | ||
} | ||
|
||
// We set the translated value in the cache only for the phrases without parameters. | ||
cacheForLocale?.set(path, translatedPhrase); | ||
cacheForLocale?.set(phraseKey, translatedPhrase); | ||
return translatedPhrase; | ||
} | ||
|
||
|
@@ -146,18 +144,18 @@ function getTranslatedPhrase<TPath extends TranslationPaths>( | |
} | ||
|
||
// Phrase is not found in full locale, search it in fallback language e.g. es | ||
const fallbackTranslatedPhrase = getTranslatedPhrase(fallbackLanguage, path, null, ...parameters); | ||
const fallbackTranslatedPhrase = getTranslatedPhrase(fallbackLanguage, phraseKey, null, ...parameters); | ||
|
||
if (fallbackTranslatedPhrase) { | ||
return fallbackTranslatedPhrase; | ||
} | ||
|
||
if (fallbackLanguage !== CONST.LOCALES.DEFAULT) { | ||
Log.alert(`${path} was not found in the ${fallbackLanguage} locale`); | ||
Log.alert(`${phraseKey} was not found in the ${fallbackLanguage} locale`); | ||
} | ||
|
||
// Phrase is not translated, search it in default language (en) | ||
return getTranslatedPhrase(CONST.LOCALES.DEFAULT, path, null, ...parameters); | ||
return getTranslatedPhrase(CONST.LOCALES.DEFAULT, phraseKey, null, ...parameters); | ||
} | ||
|
||
/** | ||
|
Unchanged files with check annotations Beta
function getOriginalMessage<T extends ReportActionName>(reportAction: OnyxInputOrEntry<ReportAction<T>>): OriginalMessage<T> | undefined { | ||
if (!Array.isArray(reportAction?.message)) { | ||
return reportAction?.message ?? reportAction?.originalMessage; | ||
} | ||
return reportAction.originalMessage; | ||
} | ||
function isExportIntegrationAction(reportAction: OnyxInputOrEntry<ReportAction>): boolean { | ||
// HACK ALERT: We're temporarily filtering out any reportActions keyed by sequenceNumber | ||
// to prevent bugs during the migration from sequenceNumber -> reportActionID | ||
if (String(reportAction.sequenceNumber) === key) { | ||
Log.info('Front-end filtered out reportAction keyed by sequenceNumber!', false, reportAction); | ||
return true; | ||
} | ||
} | ||
function getCardIssuedMessage(reportAction: OnyxEntry<ReportAction>, shouldRenderHTML = false) { | ||
const assigneeAccountID = (reportAction?.originalMessage as IssueNewCardOriginalMessage)?.assigneeAccountID; | ||
const assigneeDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([assigneeAccountID], currentUserAccountID ?? -1)[0]; | ||
const assignee = shouldRenderHTML ? `<mention-user accountID="${assigneeAccountID}"/>` : assigneeDetails?.firstName ?? assigneeDetails.login ?? ''; | ||
getNumberOfMoneyRequests, | ||
getOneTransactionThreadReportID, | ||
getOriginalMessage, | ||
getParentReportAction, | ||
Check failure on line 1757 in src/libs/ReportActionsUtils.ts
|
||
getRemovedFromApprovalChainMessage, | ||
getReportAction, | ||
getReportActionHtml, |
[customField, fieldName, fieldValue, updateRecord], | ||
); | ||
const renderMap: Record<string, JSX.Element> = { | ||
mapping: renderSelection, | ||
}; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it will be easy to implement, and we need to pass the count somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But same as the others, you could just have a string here right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
I also thought about it 5 minutes ago 😅
I will merge changes soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it will work!