refactor(client): i18n.locale -> i18n.ts
This commit is contained in:
@ -27,7 +27,7 @@ export function getNoteMenu(props: {
|
||||
function del(): void {
|
||||
os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.locale.noteDeleteConfirm,
|
||||
text: i18n.ts.noteDeleteConfirm,
|
||||
}).then(({ canceled }) => {
|
||||
if (canceled) return;
|
||||
|
||||
@ -40,7 +40,7 @@ export function getNoteMenu(props: {
|
||||
function delEdit(): void {
|
||||
os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.locale.deleteAndEditConfirm,
|
||||
text: i18n.ts.deleteAndEditConfirm,
|
||||
}).then(({ canceled }) => {
|
||||
if (canceled) return;
|
||||
|
||||
@ -87,7 +87,7 @@ export function getNoteMenu(props: {
|
||||
if (e.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: i18n.locale.pinLimitExceeded
|
||||
text: i18n.ts.pinLimitExceeded
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -97,22 +97,22 @@ export function getNoteMenu(props: {
|
||||
const clips = await os.api('clips/list');
|
||||
os.popupMenu([{
|
||||
icon: 'fas fa-plus',
|
||||
text: i18n.locale.createNew,
|
||||
text: i18n.ts.createNew,
|
||||
action: async () => {
|
||||
const { canceled, result } = await os.form(i18n.locale.createNewClip, {
|
||||
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
|
||||
name: {
|
||||
type: 'string',
|
||||
label: i18n.locale.name
|
||||
label: i18n.ts.name
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
multiline: true,
|
||||
label: i18n.locale.description
|
||||
label: i18n.ts.description
|
||||
},
|
||||
isPublic: {
|
||||
type: 'boolean',
|
||||
label: i18n.locale.public,
|
||||
label: i18n.ts.public,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
@ -133,7 +133,7 @@ export function getNoteMenu(props: {
|
||||
|
||||
async function promote(): Promise<void> {
|
||||
const { canceled, result: days } = await os.inputNumber({
|
||||
title: i18n.locale.numberOfDays,
|
||||
title: i18n.ts.numberOfDays,
|
||||
});
|
||||
|
||||
if (canceled) return;
|
||||
@ -171,69 +171,69 @@ export function getNoteMenu(props: {
|
||||
|
||||
menu = [{
|
||||
icon: 'fas fa-copy',
|
||||
text: i18n.locale.copyContent,
|
||||
text: i18n.ts.copyContent,
|
||||
action: copyContent
|
||||
}, {
|
||||
icon: 'fas fa-link',
|
||||
text: i18n.locale.copyLink,
|
||||
text: i18n.ts.copyLink,
|
||||
action: copyLink
|
||||
}, (appearNote.url || appearNote.uri) ? {
|
||||
icon: 'fas fa-external-link-square-alt',
|
||||
text: i18n.locale.showOnRemote,
|
||||
text: i18n.ts.showOnRemote,
|
||||
action: () => {
|
||||
window.open(appearNote.url || appearNote.uri, '_blank');
|
||||
}
|
||||
} : undefined,
|
||||
{
|
||||
icon: 'fas fa-share-alt',
|
||||
text: i18n.locale.share,
|
||||
text: i18n.ts.share,
|
||||
action: share
|
||||
},
|
||||
instance.translatorAvailable ? {
|
||||
icon: 'fas fa-language',
|
||||
text: i18n.locale.translate,
|
||||
text: i18n.ts.translate,
|
||||
action: translate
|
||||
} : undefined,
|
||||
null,
|
||||
statePromise.then(state => state.isFavorited ? {
|
||||
icon: 'fas fa-star',
|
||||
text: i18n.locale.unfavorite,
|
||||
text: i18n.ts.unfavorite,
|
||||
action: () => toggleFavorite(false)
|
||||
} : {
|
||||
icon: 'fas fa-star',
|
||||
text: i18n.locale.favorite,
|
||||
text: i18n.ts.favorite,
|
||||
action: () => toggleFavorite(true)
|
||||
}),
|
||||
{
|
||||
icon: 'fas fa-paperclip',
|
||||
text: i18n.locale.clip,
|
||||
text: i18n.ts.clip,
|
||||
action: () => clip()
|
||||
},
|
||||
(appearNote.userId != $i.id) ? statePromise.then(state => state.isWatching ? {
|
||||
icon: 'fas fa-eye-slash',
|
||||
text: i18n.locale.unwatch,
|
||||
text: i18n.ts.unwatch,
|
||||
action: () => toggleWatch(false)
|
||||
} : {
|
||||
icon: 'fas fa-eye',
|
||||
text: i18n.locale.watch,
|
||||
text: i18n.ts.watch,
|
||||
action: () => toggleWatch(true)
|
||||
}) : undefined,
|
||||
statePromise.then(state => state.isMutedThread ? {
|
||||
icon: 'fas fa-comment-slash',
|
||||
text: i18n.locale.unmuteThread,
|
||||
text: i18n.ts.unmuteThread,
|
||||
action: () => toggleThreadMute(false)
|
||||
} : {
|
||||
icon: 'fas fa-comment-slash',
|
||||
text: i18n.locale.muteThread,
|
||||
text: i18n.ts.muteThread,
|
||||
action: () => toggleThreadMute(true)
|
||||
}),
|
||||
appearNote.userId == $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? {
|
||||
icon: 'fas fa-thumbtack',
|
||||
text: i18n.locale.unpin,
|
||||
text: i18n.ts.unpin,
|
||||
action: () => togglePin(false)
|
||||
} : {
|
||||
icon: 'fas fa-thumbtack',
|
||||
text: i18n.locale.pin,
|
||||
text: i18n.ts.pin,
|
||||
action: () => togglePin(true)
|
||||
} : undefined,
|
||||
/*
|
||||
@ -241,7 +241,7 @@ export function getNoteMenu(props: {
|
||||
null,
|
||||
{
|
||||
icon: 'fas fa-bullhorn',
|
||||
text: i18n.locale.promote,
|
||||
text: i18n.ts.promote,
|
||||
action: promote
|
||||
}]
|
||||
: []
|
||||
@ -250,7 +250,7 @@ export function getNoteMenu(props: {
|
||||
null,
|
||||
{
|
||||
icon: 'fas fa-exclamation-circle',
|
||||
text: i18n.locale.reportAbuse,
|
||||
text: i18n.ts.reportAbuse,
|
||||
action: () => {
|
||||
const u = appearNote.url || appearNote.uri || `${url}/notes/${appearNote.id}`;
|
||||
os.popup(import('@/components/abuse-report-window.vue'), {
|
||||
@ -265,12 +265,12 @@ export function getNoteMenu(props: {
|
||||
null,
|
||||
appearNote.userId == $i.id ? {
|
||||
icon: 'fas fa-edit',
|
||||
text: i18n.locale.deleteAndEdit,
|
||||
text: i18n.ts.deleteAndEdit,
|
||||
action: delEdit
|
||||
} : undefined,
|
||||
{
|
||||
icon: 'fas fa-trash-alt',
|
||||
text: i18n.locale.delete,
|
||||
text: i18n.ts.delete,
|
||||
danger: true,
|
||||
action: del
|
||||
}]
|
||||
@ -280,15 +280,15 @@ export function getNoteMenu(props: {
|
||||
} else {
|
||||
menu = [{
|
||||
icon: 'fas fa-copy',
|
||||
text: i18n.locale.copyContent,
|
||||
text: i18n.ts.copyContent,
|
||||
action: copyContent
|
||||
}, {
|
||||
icon: 'fas fa-link',
|
||||
text: i18n.locale.copyLink,
|
||||
text: i18n.ts.copyLink,
|
||||
action: copyLink
|
||||
}, (appearNote.url || appearNote.uri) ? {
|
||||
icon: 'fas fa-external-link-square-alt',
|
||||
text: i18n.locale.showOnRemote,
|
||||
text: i18n.ts.showOnRemote,
|
||||
action: () => {
|
||||
window.open(appearNote.url || appearNote.uri, '_blank');
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ import { i18n } from '@/i18n';
|
||||
*/
|
||||
export const getNoteSummary = (note: misskey.entities.Note): string => {
|
||||
if (note.deletedAt) {
|
||||
return `(${i18n.locale.deletedNote})`;
|
||||
return `(${i18n.ts.deletedNote})`;
|
||||
}
|
||||
|
||||
if (note.isHidden) {
|
||||
return `(${i18n.locale.invisibleNote})`;
|
||||
return `(${i18n.ts.invisibleNote})`;
|
||||
}
|
||||
|
||||
let summary = '';
|
||||
@ -30,7 +30,7 @@ export const getNoteSummary = (note: misskey.entities.Note): string => {
|
||||
|
||||
// 投票が添付されているとき
|
||||
if (note.poll) {
|
||||
summary += ` (${i18n.locale.poll})`;
|
||||
summary += ` (${i18n.ts.poll})`;
|
||||
}
|
||||
|
||||
// 返信のとき
|
||||
|
@ -11,12 +11,12 @@ export function getUserMenu(user) {
|
||||
const meId = $i ? $i.id : null;
|
||||
|
||||
async function pushList() {
|
||||
const t = i18n.locale.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
|
||||
const t = i18n.ts.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
|
||||
const lists = await os.api('users/lists/list');
|
||||
if (lists.length === 0) {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: i18n.locale.youHaveNoLists
|
||||
text: i18n.ts.youHaveNoLists
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -38,12 +38,12 @@ export function getUserMenu(user) {
|
||||
if (groups.length === 0) {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: i18n.locale.youHaveNoGroups
|
||||
text: i18n.ts.youHaveNoGroups
|
||||
});
|
||||
return;
|
||||
}
|
||||
const { canceled, result: groupId } = await os.select({
|
||||
title: i18n.locale.group,
|
||||
title: i18n.ts.group,
|
||||
items: groups.map(group => ({
|
||||
value: group.id, text: group.name
|
||||
}))
|
||||
@ -64,7 +64,7 @@ export function getUserMenu(user) {
|
||||
}
|
||||
|
||||
async function toggleBlock() {
|
||||
if (!await getConfirmed(user.isBlocking ? i18n.locale.unblockConfirm : i18n.locale.blockConfirm)) return;
|
||||
if (!await getConfirmed(user.isBlocking ? i18n.ts.unblockConfirm : i18n.ts.blockConfirm)) return;
|
||||
|
||||
os.apiWithDialog(user.isBlocking ? 'blocking/delete' : 'blocking/create', {
|
||||
userId: user.id
|
||||
@ -119,70 +119,70 @@ export function getUserMenu(user) {
|
||||
|
||||
let menu = [{
|
||||
icon: 'fas fa-at',
|
||||
text: i18n.locale.copyUsername,
|
||||
text: i18n.ts.copyUsername,
|
||||
action: () => {
|
||||
copyToClipboard(`@${user.username}@${user.host || host}`);
|
||||
}
|
||||
}, {
|
||||
icon: 'fas fa-info-circle',
|
||||
text: i18n.locale.info,
|
||||
text: i18n.ts.info,
|
||||
action: () => {
|
||||
os.pageWindow(`/user-info/${user.id}`);
|
||||
}
|
||||
}, {
|
||||
icon: 'fas fa-envelope',
|
||||
text: i18n.locale.sendMessage,
|
||||
text: i18n.ts.sendMessage,
|
||||
action: () => {
|
||||
os.post({ specified: user });
|
||||
}
|
||||
}, meId != user.id ? {
|
||||
type: 'link',
|
||||
icon: 'fas fa-comments',
|
||||
text: i18n.locale.startMessaging,
|
||||
text: i18n.ts.startMessaging,
|
||||
to: '/my/messaging/' + Acct.toString(user),
|
||||
} : undefined, null, {
|
||||
icon: 'fas fa-list-ul',
|
||||
text: i18n.locale.addToList,
|
||||
text: i18n.ts.addToList,
|
||||
action: pushList
|
||||
}, meId != user.id ? {
|
||||
icon: 'fas fa-users',
|
||||
text: i18n.locale.inviteToGroup,
|
||||
text: i18n.ts.inviteToGroup,
|
||||
action: inviteGroup
|
||||
} : undefined] as any;
|
||||
|
||||
if ($i && meId != user.id) {
|
||||
menu = menu.concat([null, {
|
||||
icon: user.isMuted ? 'fas fa-eye' : 'fas fa-eye-slash',
|
||||
text: user.isMuted ? i18n.locale.unmute : i18n.locale.mute,
|
||||
text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute,
|
||||
action: toggleMute
|
||||
}, {
|
||||
icon: 'fas fa-ban',
|
||||
text: user.isBlocking ? i18n.locale.unblock : i18n.locale.block,
|
||||
text: user.isBlocking ? i18n.ts.unblock : i18n.ts.block,
|
||||
action: toggleBlock
|
||||
}]);
|
||||
|
||||
if (user.isFollowed) {
|
||||
menu = menu.concat([{
|
||||
icon: 'fas fa-unlink',
|
||||
text: i18n.locale.breakFollow,
|
||||
text: i18n.ts.breakFollow,
|
||||
action: invalidateFollow
|
||||
}]);
|
||||
}
|
||||
|
||||
menu = menu.concat([null, {
|
||||
icon: 'fas fa-exclamation-circle',
|
||||
text: i18n.locale.reportAbuse,
|
||||
text: i18n.ts.reportAbuse,
|
||||
action: reportAbuse
|
||||
}]);
|
||||
|
||||
if (iAmModerator) {
|
||||
menu = menu.concat([null, {
|
||||
icon: 'fas fa-microphone-slash',
|
||||
text: user.isSilenced ? i18n.locale.unsilence : i18n.locale.silence,
|
||||
text: user.isSilenced ? i18n.ts.unsilence : i18n.ts.silence,
|
||||
action: toggleSilence
|
||||
}, {
|
||||
icon: 'fas fa-snowflake',
|
||||
text: user.isSuspended ? i18n.locale.unsuspend : i18n.locale.suspend,
|
||||
text: user.isSuspended ? i18n.ts.unsuspend : i18n.ts.suspend,
|
||||
action: toggleSuspend
|
||||
}]);
|
||||
}
|
||||
@ -191,7 +191,7 @@ export function getUserMenu(user) {
|
||||
if ($i && meId === user.id) {
|
||||
menu = menu.concat([null, {
|
||||
icon: 'fas fa-pencil-alt',
|
||||
text: i18n.locale.editProfile,
|
||||
text: i18n.ts.editProfile,
|
||||
action: () => {
|
||||
router.push('/settings/profile');
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
export class I18n<T extends Record<string, any>> {
|
||||
public locale: T;
|
||||
public ts: T;
|
||||
|
||||
constructor(locale: T) {
|
||||
this.locale = locale;
|
||||
this.ts = locale;
|
||||
|
||||
//#region BIND
|
||||
this.t = this.t.bind(this);
|
||||
@ -11,9 +11,9 @@ export class I18n<T extends Record<string, any>> {
|
||||
|
||||
// string にしているのは、ドット区切りでのパス指定を許可するため
|
||||
// なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも
|
||||
public t(key: string, args?: Record<string, any>): string {
|
||||
public t(key: string, args?: Record<string, string>): string {
|
||||
try {
|
||||
let str = key.split('.').reduce((o, i) => o[i], this.locale) as string;
|
||||
let str = key.split('.').reduce((o, i) => o[i], this.ts) as unknown as string;
|
||||
|
||||
if (args) {
|
||||
for (const [k, v] of Object.entries(args)) {
|
||||
@ -21,7 +21,7 @@ export class I18n<T extends Record<string, any>> {
|
||||
}
|
||||
}
|
||||
return str;
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
console.warn(`missing localization '${key}'`);
|
||||
return key;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import * as os from '@/os';
|
||||
|
||||
export async function lookupUser() {
|
||||
const { canceled, result } = await os.inputText({
|
||||
title: i18n.locale.usernameOrUserId,
|
||||
title: i18n.ts.usernameOrUserId,
|
||||
});
|
||||
if (canceled) return;
|
||||
|
||||
@ -19,7 +19,7 @@ export async function lookupUser() {
|
||||
if (_notFound) {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: i18n.locale.noSuchUser
|
||||
text: i18n.ts.noSuchUser
|
||||
});
|
||||
} else {
|
||||
_notFound = true;
|
||||
|
@ -6,7 +6,7 @@ export function pleaseLogin() {
|
||||
if ($i) return;
|
||||
|
||||
alert({
|
||||
title: i18n.locale.signinRequired,
|
||||
title: i18n.ts.signinRequired,
|
||||
text: null
|
||||
});
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { router } from '@/router';
|
||||
|
||||
export async function search() {
|
||||
const { canceled, result: query } = await os.inputText({
|
||||
title: i18n.locale.search,
|
||||
title: i18n.ts.search,
|
||||
});
|
||||
if (canceled || query == null || query === '') return;
|
||||
|
||||
@ -46,7 +46,7 @@ export async function search() {
|
||||
uri: q
|
||||
});
|
||||
|
||||
os.promiseDialog(promise, null, null, i18n.locale.fetchingAsApObject);
|
||||
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
||||
|
||||
const res = await promise;
|
||||
|
||||
|
@ -41,9 +41,9 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
|
||||
|
||||
const chooseFileFromUrl = () => {
|
||||
os.inputText({
|
||||
title: i18n.locale.uploadFromUrl,
|
||||
title: i18n.ts.uploadFromUrl,
|
||||
type: 'url',
|
||||
placeholder: i18n.locale.uploadFromUrlDescription
|
||||
placeholder: i18n.ts.uploadFromUrlDescription
|
||||
}).then(({ canceled, result: url }) => {
|
||||
if (canceled) return;
|
||||
|
||||
@ -64,8 +64,8 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
|
||||
});
|
||||
|
||||
os.alert({
|
||||
title: i18n.locale.uploadFromUrlRequested,
|
||||
text: i18n.locale.uploadFromUrlMayTakeTime
|
||||
title: i18n.ts.uploadFromUrlRequested,
|
||||
text: i18n.ts.uploadFromUrlMayTakeTime
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -74,15 +74,15 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
|
||||
text: label,
|
||||
type: 'label'
|
||||
} : undefined, {
|
||||
text: i18n.locale.upload,
|
||||
text: i18n.ts.upload,
|
||||
icon: 'fas fa-upload',
|
||||
action: chooseFileFromPc
|
||||
}, {
|
||||
text: i18n.locale.fromDrive,
|
||||
text: i18n.ts.fromDrive,
|
||||
icon: 'fas fa-cloud',
|
||||
action: chooseFileFromDrive
|
||||
}, {
|
||||
text: i18n.locale.fromUrl,
|
||||
text: i18n.ts.fromUrl,
|
||||
icon: 'fas fa-link',
|
||||
action: chooseFileFromUrl
|
||||
}], src);
|
||||
|
@ -4,7 +4,7 @@ import { i18n } from '@/i18n';
|
||||
export function showSuspendedDialog() {
|
||||
return os.alert({
|
||||
type: 'error',
|
||||
title: i18n.locale.yourAccountSuspendedTitle,
|
||||
text: i18n.locale.yourAccountSuspendedDescription
|
||||
title: i18n.ts.yourAccountSuspendedTitle,
|
||||
text: i18n.ts.yourAccountSuspendedDescription
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export function useLeaveGuard(enabled: Ref<boolean>) {
|
||||
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.locale.leaveConfirm,
|
||||
text: i18n.ts.leaveConfirm,
|
||||
});
|
||||
|
||||
return canceled;
|
||||
@ -23,7 +23,7 @@ export function useLeaveGuard(enabled: Ref<boolean>) {
|
||||
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.locale.leaveConfirm,
|
||||
text: i18n.ts.leaveConfirm,
|
||||
});
|
||||
|
||||
return !canceled;
|
||||
|
Reference in New Issue
Block a user