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

fix: add missing translation function on report related documents #32713

Merged
merged 10 commits into from
Nov 3, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ def setup_ageing_columns(self):
"{range3}-{range4}".format(
range3=cint(self.filters["range3"]) + 1, range4=self.filters["range4"]
),
"{range4}-{above}".format(range4=cint(self.filters["range4"]) + 1, above=_("Above")),
_("{range4}-Above").format(range4=cint(self.filters["range4"]) + 1),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing this way are more control to translation, example in spanish i would translate this as "90 días a más" or "mayor a 90 días"

]
):
self.add_column(label=label, fieldname="range" + str(i + 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ frappe.query_reports["Budget Variance Report"] = {
"formatter": function (value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data);

if (column.fieldname.includes('variance')) {
if (column.fieldname.includes(__("variance"))) {
Copy link
Member

Choose a reason for hiding this comment

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

@ernestoruiz89 This is not a user-facing string. Its an internal field name, it should not be translated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is not translated it does not work, because the field is translated from python

image


if (data[column.fieldname] < 0) {
value = "<span style='color:red'>" + value + "</span>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def get_chart_data(filters, columns, data):
"data": {
"labels": labels,
"datasets": [
{"name": "Budget", "chartType": "bar", "values": budget_values},
{"name": "Actual Expense", "chartType": "bar", "values": actual_values},
{"name": _("Budget"), "chartType": "bar", "values": budget_values},
{"name": _("Actual Expense"), "chartType": "bar", "values": actual_values},
],
},
"type": "bar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def prepare_chart(self):
"labels": [period.label for period in self.period_list],
"datasets": [
{
"name": "Actual Posting",
"name": _("Actual Posting"),
"chartType": "bar",
"values": [x.actual for x in self.period_total],
}
Expand All @@ -410,7 +410,7 @@ def prepare_chart(self):

if self.filters.with_upcoming_postings:
chart["data"]["datasets"].append(
{"name": "Expected", "chartType": "line", "values": [x.total for x in self.period_total]}
{"name": _("Expected"), "chartType": "line", "values": [x.total for x in self.period_total]}
)

return chart
Expand Down
8 changes: 5 additions & 3 deletions erpnext/selling/report/sales_analytics/sales_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,13 @@ def get_periodic_data(self):

def get_period(self, posting_date):
if self.filters.range == "Weekly":
period = "Week " + str(posting_date.isocalendar()[1]) + " " + str(posting_date.year)
period = _("Week {0} {1}").format(str(posting_date.isocalendar()[1]), str(posting_date.year))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleaner code

elif self.filters.range == "Monthly":
period = str(self.months[posting_date.month - 1]) + " " + str(posting_date.year)
period = _(str(self.months[posting_date.month - 1])) + " " + str(posting_date.year)
elif self.filters.range == "Quarterly":
period = "Quarter " + str(((posting_date.month - 1) // 3) + 1) + " " + str(posting_date.year)
period = _("Quarter {0} {1}").format(
str(((posting_date.month - 1) // 3) + 1), str(posting_date.year)
)
else:
year = get_fiscal_year(posting_date, company=self.filters.company)
period = str(year[0])
Expand Down
4 changes: 2 additions & 2 deletions erpnext/stock/report/stock_ageing/stock_ageing.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ def setup_ageing_columns(filters: Filters, range_columns: List):
f"0 - {filters['range1']}",
f"{cint(filters['range1']) + 1} - {cint(filters['range2'])}",
f"{cint(filters['range2']) + 1} - {cint(filters['range3'])}",
f"{cint(filters['range3']) + 1} - {_('Above')}",
_("{0} - Above").format(cint(filters["range3"]) + 1),
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing this way are more control to translation, example in spanish i would translate this as "90 días a más" or "mayor a 90 días"

for i, label in enumerate(ranges):
fieldname = "range" + str(i + 1)
add_column(range_columns, label=f"Age ({label})", fieldname=fieldname)
add_column(range_columns, label=_("Age ({0})").format(label), fieldname=fieldname)


def add_column(
Expand Down
8 changes: 5 additions & 3 deletions erpnext/stock/report/stock_analytics/stock_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ def get_period(posting_date, filters):
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

if filters.range == "Weekly":
period = "Week " + str(posting_date.isocalendar()[1]) + " " + str(posting_date.year)
period = _("Week {0} {1}").format(str(posting_date.isocalendar()[1]), str(posting_date.year))
elif filters.range == "Monthly":
period = str(months[posting_date.month - 1]) + " " + str(posting_date.year)
period = _(str(months[posting_date.month - 1])) + " " + str(posting_date.year)
elif filters.range == "Quarterly":
period = "Quarter " + str(((posting_date.month - 1) // 3) + 1) + " " + str(posting_date.year)
period = _("Quarter {0} {1}").format(
str(((posting_date.month - 1) // 3) + 1), str(posting_date.year)
)
else:
year = get_fiscal_year(posting_date, company=filters.company)
period = str(year[2])
Expand Down