mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 19:13:55 +08:00
feat(note_language): align list of languages to the right
This commit is contained in:
parent
856410120c
commit
951f4c4921
@ -2,15 +2,10 @@ import options from "./options.js";
|
|||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import i18nextHttpBackend from "i18next-http-backend";
|
import i18nextHttpBackend from "i18next-http-backend";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
|
import type { Locale } from "../../../services/i18n.js";
|
||||||
|
|
||||||
let locales: Locale[] | null;
|
let locales: Locale[] | null;
|
||||||
|
|
||||||
// TODO: Deduplicate with server.
|
|
||||||
export interface Locale {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function initLocale() {
|
export async function initLocale() {
|
||||||
const locale = (options.get("locale") as string) || "en";
|
const locale = (options.get("locale") as string) || "en";
|
||||||
|
|
||||||
@ -28,7 +23,7 @@ export async function initLocale() {
|
|||||||
|
|
||||||
export function getAvailableLocales() {
|
export function getAvailableLocales() {
|
||||||
if (!locales) {
|
if (!locales) {
|
||||||
throw new Error("Tried to load list of locales, but localization is not yet initialized.");
|
throw new Error("Tried to load list of locales, but localization is not yet initialized.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return locales;
|
return locales;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Dropdown } from "bootstrap";
|
import { Dropdown } from "bootstrap";
|
||||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||||
import { getAvailableLocales, type Locale } from "../services/i18n.js";
|
import { getAvailableLocales } from "../services/i18n.js";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import type { EventData } from "../components/app_context.js";
|
import type { EventData } from "../components/app_context.js";
|
||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
import attributes from "../services/attributes.js";
|
import attributes from "../services/attributes.js";
|
||||||
|
import type { Locale } from "../../../services/i18n.js";
|
||||||
|
|
||||||
const TPL = `\
|
const TPL = `\
|
||||||
<div class="dropdown note-language-widget">
|
<div class="dropdown note-language-widget">
|
||||||
@ -13,6 +14,12 @@ const TPL = `\
|
|||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="note-language-dropdown dropdown-menu dropdown-menu-left tn-dropdown-list"></div>
|
<div class="note-language-dropdown dropdown-menu dropdown-menu-left tn-dropdown-list"></div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.note-language-dropdown [dir=rtl] {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -56,6 +63,10 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
|
|||||||
for (const locale of this.locales) {
|
for (const locale of this.locales) {
|
||||||
if (typeof locale === "object") {
|
if (typeof locale === "object") {
|
||||||
const $title = $("<span>").text(locale.name);
|
const $title = $("<span>").text(locale.name);
|
||||||
|
if (locale.rtl) {
|
||||||
|
$title.attr("dir", "rtl");
|
||||||
|
}
|
||||||
|
|
||||||
const $link = $('<a class="dropdown-item">')
|
const $link = $('<a class="dropdown-item">')
|
||||||
.attr("data-language", locale.id)
|
.attr("data-language", locale.id)
|
||||||
.append('<span class="check">✓</span> ')
|
.append('<span class="check">✓</span> ')
|
||||||
@ -64,6 +75,7 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
|
|||||||
const languageId = $link.attr("data-language") ?? "";
|
const languageId = $link.attr("data-language") ?? "";
|
||||||
this.save(languageId);
|
this.save(languageId);
|
||||||
})
|
})
|
||||||
|
|
||||||
this.$noteLanguageDropdown.append($link);
|
this.$noteLanguageDropdown.append($link);
|
||||||
} else {
|
} else {
|
||||||
this.$noteLanguageDropdown.append('<div class="dropdown-divider"></div>');
|
this.$noteLanguageDropdown.append('<div class="dropdown-divider"></div>');
|
||||||
|
@ -6,6 +6,13 @@ import { join } from "path";
|
|||||||
import { getResourceDir } from "./utils.js";
|
import { getResourceDir } from "./utils.js";
|
||||||
import hidden_subtree from "./hidden_subtree.js";
|
import hidden_subtree from "./hidden_subtree.js";
|
||||||
|
|
||||||
|
export interface Locale {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
/** `true` if the language is a right-to-left one, or `false` if it's left-to-right. */
|
||||||
|
rtl?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export async function initializeTranslations() {
|
export async function initializeTranslations() {
|
||||||
const resourceDir = getResourceDir();
|
const resourceDir = getResourceDir();
|
||||||
|
|
||||||
@ -20,7 +27,7 @@ export async function initializeTranslations() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLocales() {
|
export function getLocales(): Locale[] {
|
||||||
// TODO: Currently hardcoded, needs to read the list of available languages.
|
// TODO: Currently hardcoded, needs to read the list of available languages.
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -59,19 +66,23 @@ export function getLocales() {
|
|||||||
*/
|
*/
|
||||||
{ // Arabic
|
{ // Arabic
|
||||||
id: "ar",
|
id: "ar",
|
||||||
name: "اَلْعَرَبِيَّةُ"
|
name: "اَلْعَرَبِيَّةُ",
|
||||||
|
rtl: true
|
||||||
},
|
},
|
||||||
{ // Hebrew
|
{ // Hebrew
|
||||||
id: "he",
|
id: "he",
|
||||||
name: "עברית"
|
name: "עברית",
|
||||||
|
rtl: true
|
||||||
},
|
},
|
||||||
{ // Kurdish
|
{ // Kurdish
|
||||||
id: "ku",
|
id: "ku",
|
||||||
name: "کوردی"
|
name: "کوردی",
|
||||||
|
rtl: true
|
||||||
},
|
},
|
||||||
{ // Persian
|
{ // Persian
|
||||||
id: "fa",
|
id: "fa",
|
||||||
name: "فارسی"
|
name: "فارسی",
|
||||||
|
rtl: true
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user