Skip to content
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

SRV-872 feat - better translations for comparison table #39

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ function addLocaleData(data: LocaleData) {
}

function t(input: string, ...args: unknown[]) {
return getInstance().translate(input, ...args);
try {
return getInstance().translate(input, ...args);
} catch (e) {
return `${input}`
}
}

function tn(key: string, ...args: unknown[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ export default function TableChart<D extends DataRecord = DataRecord>(
} = props;
const comparisonColumns = [
{ key: 'all', label: t('Display all') },
{ key: '#', label: '#' },
{ key: '△', label: '△' },
{ key: '%', label: '%' },
{ key: t('sv_previous'), label: t('sv_previous') },
{ key: t('sv_change') , label: t('sv_change') },
{ key: t('sv_change_percentage') label: t('sv_change_percentage') },
];
const timestampFormatter = useCallback(
value => getTimeFormatterForGranularity(timeGrain)(value),
Expand Down Expand Up @@ -404,7 +404,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
};
};

const comparisonLabels = [t('Main'), '#', '△', '%'];
const comparisonLabels = [t('sv_current'), t('sv_previous'), t('sv_change'), t('sv_change_percentage')];
const filteredColumnsMeta = useMemo(() => {
if (!isUsingTimeComparison) {
return columnsMeta;
Expand Down
56 changes: 28 additions & 28 deletions superset-frontend/plugins/plugin-chart-table/src/transformProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ const processComparisonTotals = (
totals.map((totalRecord: DataRecord) =>
Object.keys(totalRecord).forEach(key => {
if (totalRecord[key] !== undefined && !key.includes(comparisonSuffix)) {
transformedTotals[`Main ${key}`] =
parseInt(transformedTotals[`Main ${key}`]?.toString() || '0', 10) +
transformedTotals[`${t('sv_current')} ${key}`] =
parseInt(transformedTotals[`${t('sv_current')} ${key}`]?.toString() || '0', 10) +
parseInt(totalRecord[key]?.toString() || '0', 10);
transformedTotals[`# ${key}`] =
parseInt(transformedTotals[`# ${key}`]?.toString() || '0', 10) +
transformedTotals[`${t('sv_previous')} ${key}`] =
parseInt(transformedTotals[`${t('sv_previous')} ${key}`]?.toString() || '0', 10) +
parseInt(
totalRecord[`${key}__${comparisonSuffix}`]?.toString() || '0',
10,
);
const { valueDifference, percentDifferenceNum } = calculateDifferences(
transformedTotals[`Main ${key}`] as number,
transformedTotals[`# ${key}`] as number,
transformedTotals[`${t('sv_current')} ${key}`] as number,
transformedTotals[`${t('sv_previous')} ${key}`] as number,
);
transformedTotals[` ${key}`] = valueDifference;
transformedTotals[`% ${key}`] = percentDifferenceNum;
transformedTotals[`${t('sv_change')} ${key}`] = valueDifference;
transformedTotals[`${t('sv_change_percentage')} ${key}`] = percentDifferenceNum;
}
}),
);
Expand Down Expand Up @@ -166,10 +166,10 @@ const processComparisonDataRecords = memoizeOne(
comparisonValue as number,
);

transformedItem[`Main ${origCol.key}`] = originalValue;
transformedItem[`# ${origCol.key}`] = comparisonValue;
transformedItem[` ${origCol.key}`] = valueDifference;
transformedItem[`% ${origCol.key}`] = percentDifferenceNum;
transformedItem[`${t('sv_current')} ${origCol.key}`] = originalValue;
transformedItem[`${t('sv_previous')} ${origCol.key}`] = comparisonValue;
transformedItem[`${t('sv_change')} ${origCol.key}`] = valueDifference;
transformedItem[`${t('sv_change_percentage')} ${origCol.key}`] = percentDifferenceNum;
}
});

Expand Down Expand Up @@ -355,11 +355,11 @@ const processComparisonColumns = (
return [
{
...col,
label: t('Main'),
key: `${t('Main')} ${col.key}`,
config: getComparisonColConfig(t('Main'), col.key, columnConfig),
label: t('sv_current'),
key: `${t('sv_current')} ${col.key}`,
config: getComparisonColConfig(t('sv_current'), col.key, columnConfig),
formatter: getComparisonColFormatter(
t('Main'),
t('sv_current'),
col,
columnConfig,
savedFormat,
Expand All @@ -368,11 +368,11 @@ const processComparisonColumns = (
},
{
...col,
label: `#`,
key: `# ${col.key}`,
config: getComparisonColConfig(`#`, col.key, columnConfig),
label: t('sv_previous'),
key: `${t('sv_previous')} ${col.key}`,
config: getComparisonColConfig(t('sv_previous'), col.key, columnConfig),
formatter: getComparisonColFormatter(
`#`,
t('sv_previous'),
col,
columnConfig,
savedFormat,
Expand All @@ -381,11 +381,11 @@ const processComparisonColumns = (
},
{
...col,
label: `△`,
key: ` ${col.key}`,
config: getComparisonColConfig(`△`, col.key, columnConfig),
label: t('sv_change'),
key: `${t('sv_change')} ${col.key}`,
config: getComparisonColConfig(t('sv_change'), col.key, columnConfig),
formatter: getComparisonColFormatter(
`△`,
t('sv_change'),
col,
columnConfig,
savedFormat,
Expand All @@ -394,11 +394,11 @@ const processComparisonColumns = (
},
{
...col,
label: `%`,
key: `% ${col.key}`,
config: getComparisonColConfig(`%`, col.key, columnConfig),
label: t('sv_change_percentage'),
key: `${t('sv_change_percentage')} ${col.key}`,
config: getComparisonColConfig(t('sv_change_percentage'), col.key, columnConfig),
formatter: getComparisonColFormatter(
`%`,
t('sv_change_percentage'),
col,
columnConfig,
savedFormat,
Expand Down
4 changes: 2 additions & 2 deletions superset/translations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_language_pack(locale: str) -> Optional[dict[str, Any]]:
pack = ALL_LANGUAGE_PACKS.get(locale)
if not pack:
filename = DIR + f"/{locale}/LC_MESSAGES/messages.json"
if not locale or locale == "en":
if not locale:
# Forcing a dummy, quasy-empty language pack for English since the file
# in the en directory is contains data with empty mappings
filename = DIR + "/empty_language_pack.json"
Expand All @@ -50,5 +50,5 @@ def get_language_pack(locale: str) -> Optional[dict[str, Any]]:
logger.error(
"Error loading language pack for, falling back on en %s", locale
)
pack = get_language_pack("en")
pack = get_language_pack('')
return pack
Loading