mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-24 09:37:05 +08:00
This PR adds localized language names to settings. The language names
are localized in the frontend, not the backend, due to setting
initialization complexity.
This change affects these areas:
- `SiteSetting.available_locales`
- this "setting" is a lookup table to get language names. use
`languageNameLookup` service to get the name for a locale
- it returns an object that looks like the following, then gets
re-hydrated with client localized values when initializing the
`siteSettingService` in the frontend.
```
[
{"native_name":"اللغة العربية","value":"ar","name":"languages.ar.name"},
...
]
```
- `SiteSetting.default_locale`
- this is a single-value `enum` setting that has always been hardcoded.
This caused quite an issue as it is not initialized the same way as
other site settings in the yml file. It has always relied on reading
directly from a `names.yml` file to load native language names, thus
bypassing the need for I18n to be initialized from the backend. A new
locale_enum type has been introduced for this setting, and any future
settings.
- `SiteSetting.content_localization_supported_locales` - this is a
`enum_list` setting,
- enum_list is introduced, leveraging both `list` and `enum`
- theme translations
- site texts
- Wizard's default_locale choices
- it was set up from the backend using `LocaleSiteSetting.value`. This
proved problematic, as a Japanese user would be getting the locales in
English because the values are initialized using English even without
memoization
- therefore we're now initializing the choices in the frontend using
`available_locales` as defined above
- content localization meta data
- post language in the composer, localization composer, post history
modal, post language tooltip, language switcher
/t/151409
77 lines
2.3 KiB
JavaScript
Vendored
77 lines
2.3 KiB
JavaScript
Vendored
import { click, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
|
|
|
acceptance("Admin - Discourse Calendar - Holidays", function (needs) {
|
|
needs.user();
|
|
needs.settings({
|
|
calendar_enabled: true,
|
|
available_locales: [{ name: "English", value: "en" }],
|
|
});
|
|
|
|
needs.pretender((server, helper) => {
|
|
server.get("/admin/discourse-calendar/holiday-regions/ca/holidays", () => {
|
|
return helper.response({
|
|
holidays: [
|
|
{ date: "2022-01-01", name: "New Year's Day" },
|
|
{ date: "2022-04-15", name: "Good Friday" },
|
|
],
|
|
});
|
|
});
|
|
|
|
server.post("/admin/discourse-calendar/holidays/disable", () => {
|
|
return helper.response({ success: "OK" });
|
|
});
|
|
|
|
server.delete("/admin/discourse-calendar/holidays/enable", () => {
|
|
return helper.response({ success: "OK" });
|
|
});
|
|
});
|
|
|
|
test("viewing holidays for a selected region", async (assert) => {
|
|
const regions = selectKit(".region-input");
|
|
|
|
await visit("/admin/plugins/calendar");
|
|
await regions.expand();
|
|
await regions.selectRowByValue("ca");
|
|
|
|
assert
|
|
.dom(".holidays-list")
|
|
.includesText("New Year's Day", "it displays holiday names");
|
|
assert
|
|
.dom(".holidays-list")
|
|
.includesText("Good Friday", "it displays holiday names");
|
|
|
|
assert
|
|
.dom(".holidays-list")
|
|
.includesText("2022-01-01", "it displays holiday dates");
|
|
assert
|
|
.dom(".holidays-list")
|
|
.includesText("2022-04-15", "it displays holiday dates");
|
|
});
|
|
|
|
test("disabling and enabling a holiday", async (assert) => {
|
|
const regions = selectKit(".region-input");
|
|
|
|
await visit("/admin/plugins/calendar");
|
|
await regions.expand();
|
|
await regions.selectRowByValue("ca");
|
|
|
|
await click("table tbody tr button");
|
|
assert
|
|
.dom("table tbody tr")
|
|
.hasClass(
|
|
"disabled",
|
|
"after clicking the disable button, it adds a .disabled CSS class"
|
|
);
|
|
|
|
await click("table tr.disabled button");
|
|
assert
|
|
.dom("table tbody tr")
|
|
.doesNotHaveClass(
|
|
"disabled",
|
|
"after clicking the enable button, it removes the .disabled CSS class"
|
|
);
|
|
});
|
|
});
|