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

chore(translations): Add missing i18n #17525

Merged
merged 10 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion superset-frontend/src/components/Menu/MenuRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ const RightMenu = ({
)}
</SubMenu>
)}
<SubMenu title="Settings" icon={<Icons.TriangleDown iconSize="xl" />}>
<SubMenu
title={t('Settings')}
icon={<Icons.TriangleDown iconSize="xl" />}
>
{settings.map((section, index) => [
<Menu.ItemGroup key={`${section.label}`} title={section.label}>
{section.childs?.map(child => {
Expand Down
8 changes: 4 additions & 4 deletions superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ const getEntityUrl = (entity: ActivityObject) => {

const getEntityLastActionOn = (entity: ActivityObject) => {
// translation keys for last action on
const LAST_VIEWED = `Viewed %s`;
const LAST_MODIFIED = `Modified %s`;
const LAST_VIEWED = 'Viewed %s';
const LAST_MODIFIED = 'Modified %s';

// for Recent viewed items
if ('time_delta_humanized' in entity) {
return t(LAST_VIEWED, entity.time_delta_humanized);
return t('Viewed %s', entity.time_delta_humanized);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this change is necessary - I assume the variable value should be picked up here. Did you check if that's not the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified, but using constants, the string was not extracted. gilbsgilbs/babel-plugin-i18next-extract#109 seems to confirm this, though the FAQ only speaks of variables, not constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, this whole section seems to rely on time_delta_humanized and changed_on_delta_humanized being localized, which apparently is not the case:

grafik

For other tables/columns, this seems to be handled differently:
grafik

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Maybe I need to switch my local devenv to non-english to catch these, too. It's becoming apparent we need a proper developer tutorial for i18n, as it's obvious this is not being handled consistently across the app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid duplication and risk of these falling out of sync, maybe we should introduce a similar localized translation mapping as I did in the previous PR:

const welcomeTableLabels: Record<WelcomeTable, string> = {
[WelcomeTable.Charts]: t('charts'),
[WelcomeTable.Dashboards]: t('dashboards'),
[WelcomeTable.Recents]: t('recents'),
[WelcomeTable.SavedQueries]: t('saved queries'),
};

Regarding time_delta_humanized, I'm pretty sure these are happening in the backend, let me look at those (I have a faint memory of when those were introduced).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why time_delta_humanized and changed_on_delta_humanized are necessary? moment.fromNow seems to localize pretty well. Aren't time / changed_on / changed_on_utc avaible for every item? Code would become more compact:

const getEntityLastActionOn = (entity: ActivityObject) => {
  if ('time' in entity) {
    return t('Viewed %s', moment(entity.time).fromNow());
  }

  let time: number | string | undefined | null;
  if ('changed_on' in entity) time = entity.changed_on;
  if ('changed_on_utc' in entity) time = entity.changed_on_utc;
  return t('Modified %s', time == null ? UNKNOWN_TIME : moment(time).fromNow(),);
};

}

if ('changed_on_delta_humanized' in entity) {
return t(LAST_MODIFIED, entity.changed_on_delta_humanized);
return t('Modified %s', entity.changed_on_delta_humanized);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

}

let time: number | string | undefined | null;
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/views/CRUD/welcome/ChartTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function ChartTable({
},
},
{
name: 'View All »',
name: t('View All »'),
buttonStyle: 'link',
onClick: () => {
const target =
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function DashboardTable({
name: (
<>
<i className="fa fa-plus" />
Dashboard
{t('Dashboard')}
</>
),
buttonStyle: 'tertiary',
Expand All @@ -216,7 +216,7 @@ function DashboardTable({
},
},
{
name: 'View All »',
name: t('View All »'),
buttonStyle: 'link',
onClick: () => {
const target =
Expand Down
7 changes: 3 additions & 4 deletions superset-frontend/src/views/CRUD/welcome/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ export default function EmptyState({ tableName, tab }: EmptyStateProps) {
window.location.href = favRedirects[tableName];
}}
>
See all{' '}
{tableName === 'SAVED_QUERIES'
? t('SQL Lab queries')
: t(`${tableName}`)}
{t('See all %(tableName)s', {
tableName: welcomeTableLabels[tableName],
villebro marked this conversation as resolved.
Show resolved Hide resolved
})}
</Button>
</Empty>
</EmptyContainer>
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const SavedQueries = ({
name: (
<>
<i className="fa fa-plus" />
SQL Query
{t('SQL Query')}
</>
),
buttonStyle: 'tertiary',
Expand All @@ -293,7 +293,7 @@ const SavedQueries = ({
},
},
{
name: 'View All »',
name: t('View All »'),
buttonStyle: 'link',
onClick: () => {
window.location.href = '/savedqueryview/list';
Expand Down
1 change: 1 addition & 0 deletions superset/translations/babel.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[jinja2: superset/**/templates/**.html]
[javascript: superset-frontend/src/**.js]
[javascript: superset-frontend/src/**.jsx]
[javascript: superset-frontend/src/**.ts]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhaoyongjie let's make sure translations are properly handled after monorepo lands!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@villebro I have rebase master on stage-2 PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add plugins and packages to babel.cfg

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool thanks @zhaoyongjie !

[javascript: superset-frontend/src/**.tsx]

encoding = utf-8
Loading