slightly better status, internationalization

This commit is contained in:
sam 2023-12-20 03:24:38 +01:00
parent 7c5acad535
commit a06dd22da4
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
22 changed files with 2416 additions and 1009 deletions

View file

@ -1,15 +1,15 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript",
"@vue/eslint-config-prettier/skip-formatting",
],
parserOptions: {
ecmaVersion: 'latest'
}
}
ecmaVersion: "latest",
},
};

View file

@ -13,8 +13,8 @@ TypeScript cannot handle type information for `.vue` imports by default, so we r
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
## Customize configuration

1
env.d.ts vendored
View file

@ -1 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="@modyfi/vite-plugin-yaml/modules" />

View file

@ -1,9 +1,9 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>

View file

@ -10,9 +10,10 @@
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
"format": "prettier --write ."
},
"dependencies": {
"@tabler/icons-vue": "^2.44.0",
"axios": "^1.6.2",
"flowbite": "^2.2.1",
"flowbite-vue": "^0.1.2",
@ -20,9 +21,11 @@
"sass": "^1.69.5",
"swrv": "^1.0.4",
"vue": "^3.3.11",
"vue-i18n": "9",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@modyfi/vite-plugin-yaml": "^1.0.4",
"@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.19.3",

File diff suppressed because it is too large Load diff

View file

@ -3,4 +3,4 @@ export default {
tailwindcss: {},
autoprefixer: {},
},
}
};

View file

@ -1,7 +1,36 @@
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import type Activity from "@/lib/api/entities/activity";
import { IconWorld, IconHome, IconLock, IconMail } from "@tabler/icons-vue";
const { t } = useI18n();
defineProps<{ status: Activity }>();
const statusScopeKey = ({ visibility }: Activity) => {
switch (visibility) {
case "direct":
return "status.visibility.directMessage";
case "private":
return "status.visibility.followersOnly";
case "unlisted":
return "status.visibility.unlisted";
case "public":
return "status.visibility.public";
}
};
const statusScopeIcon = ({ visibility }: Activity) => {
switch (visibility) {
case "direct":
return IconMail
case "private":
return IconLock
case "unlisted":
return IconHome
case "public":
return IconWorld
}
}
</script>
<template>
@ -12,8 +41,8 @@ defineProps<{ status: Activity }>();
class="rounded-full m-2"
:src="status.account.avatar"
width="64"
alt="Avatar for {{ status.account.acct }}"
title="Avatar for {{ status.account.acct }}"
:alt="t('status.avatar', { name: status.account.acct })"
:title="t('status.avatar', { name: status.account.acct })"
/>
</RouterLink>
<div class="flex flex-col my-1">
@ -29,11 +58,10 @@ defineProps<{ status: Activity }>();
</div>
<div class="my-1 flex flex-row">
<span>
<span title="{t(statusScopeKey(status))}" aria-hidden="true">
<!-- <StatusScopeIcon status="{status}" /> -->
Public
<span :title="t(statusScopeKey(status))" aria-hidden="true">
<component :is="statusScopeIcon(status)" />
</span>
<span class="sr-only">{t(statusScopeKey(status))}</span>
<span class="sr-only">{{ t(statusScopeKey(status)) }}</span>
</span>
<RouterLink :to="`/@${status.account.acct}/statuses/${status.id}`">
{humanizeDuration(time)}

35
src/i18n.ts Normal file
View file

@ -0,0 +1,35 @@
import { nextTick } from "vue";
import { createI18n } from "vue-i18n";
import en from "./locale/en.yaml";
export const supportedLocales = ["en", "en-PR"];
export const i18n = createI18n({
legacy: false,
locale: "en",
messages: {
en: en,
},
});
export function setLanguage(locale: string) {
// @ts-ignore
i18n.global.locale.value = locale;
document.querySelector("html")!.setAttribute("lang", locale);
}
export async function loadLocale(locale: string) {
// Check if the locale is already loaded. If not, return
// @ts-ignore
if (i18n.global.availableLocales.indexOf(locale) !== -1) return;
if (supportedLocales.indexOf(locale) === -1) throw `${locale} is not a valid locale`;
const messages = await locales[locale as keyof typeof locales]();
i18n.global.setLocaleMessage(locale, messages.default);
return nextTick();
}
const locales = {
"en-PR": () => import("./locale/en.pirate.yaml"),
};

32
src/locale/en.pirate.yaml Normal file
View file

@ -0,0 +1,32 @@
status:
avatar: "{name}'s mugshot"
characterCount: "{count} character | {count} characters"
showContent: "Show treasure ({@:status.characterCount})"
hideContent: "Hide treasure ({@:status.characterCount})"
visibility:
directMessage: Direct bottle
followersOnly: Only shown to their mateys
unlisted: Quietly thrown in the sea
public: Free as the wind
navbar:
homeTimeine: Yar friends' bottles
localTimeline: Ship's bottles
bubbleTimeline: Fleet's bottles
globalTimeline: The seven seas
settings: Yar pref'rences
login: Report fer duty
logout: Go to sleep
settings:
darkTheme: Like the moon's out
lightTheme: Like the sun's out
sidebar:
postbox:
placeholder: What be happening on deck?
postButton: Roll up an' send
directMessage: Direct bottle
followersOnly: Only send to yer mateys
unlisted: Quietly throw in the sea
public: Post free as the wind
emojiButton: Draw lil' faces
pollButton: Start a vote
fileButton: Draw images

32
src/locale/en.yaml Normal file
View file

@ -0,0 +1,32 @@
status:
avatar: "{name}'s avatar"
characterCount: "{count} character | {count} characters"
showContent: "Show content ({@:status.characterCount})"
hideContent: "Hide content ({@:status.characterCount})"
visibility:
directMessage: Direct message
followersOnly: Followers only
unlisted: Unlisted
public: Public
navbar:
homeTimeine: Home timeline
localTimeline: Local timeline
bubbleTimeline: Bubble timeline
globalTimeline: Global timeline
settings: Settings
login: Log in
logout: Log out
settings:
darkTheme: Dark theme
lightTheme: Light theme
sidebar:
postbox:
placeholder: What's going on?
postButton: Post
directMessage: Direct message
followersOnly: Followers only
unlisted: Unlisted
public: Public
emojiButton: Emoji
pollButton: Create poll
fileButton: Attach a file

View file

@ -2,6 +2,7 @@ import "./assets/style.css";
import { createApp } from "vue";
import { createPinia } from "pinia";
import { i18n } from "./i18n";
import App from "./App.vue";
import router from "./router";
@ -10,5 +11,6 @@ const app = createApp(App);
app.use(createPinia());
app.use(router);
app.use(i18n);
app.mount("#app");

View file

@ -6,7 +6,7 @@ import { ref } from "vue";
const localStorageKey = "vulpine-oauth-app";
export const useAppStore = defineStore("oauth-app", () => {
const json = localStorage.getItem(localStorageKey)
const json = localStorage.getItem(localStorageKey);
const app = ref<Application>(json ? JSON.parse(json) : undefined);
async function getApp() {
@ -18,12 +18,12 @@ export const useAppStore = defineStore("oauth-app", () => {
client_name: "vulpine-fe",
redirect_uris: `${window.location.origin}/auth/callback`,
scopes: "read write follow push",
}
})
},
});
app.value = resp;
localStorage.setItem(localStorageKey, JSON.stringify(resp));
return app.value;
}
return { app, getApp }
})
return { app, getApp };
});

View file

@ -35,6 +35,7 @@ watch(
},
);
</script>
<template>
<div v-if="error">Failed to load: {{ error }}</div>
<FwbSpinner v-else-if="!data" size="10" />

View file

@ -4,11 +4,11 @@ export default {
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
'node_modules/flowbite-vue/**/*.{js,jsx,ts,tsx,vue}',
'node_modules/flowbite/**/*.{js,jsx,ts,tsx}',
"node_modules/flowbite-vue/**/*.{js,jsx,ts,tsx,vue}",
"node_modules/flowbite/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [import('flowbite/plugin')],
}
plugins: [import("flowbite/plugin")],
};

View file

@ -2,13 +2,14 @@ import { fileURLToPath, URL } from "node:url";
import { loadEnv, defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import yaml from "@modyfi/vite-plugin-yaml";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const { INSTANCE } = loadEnv(mode, process.cwd(), "");
return {
plugins: [vue()],
plugins: [vue(), yaml()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),