Skip to content

Commit e244745

Browse files
committed
i18n plugin progress
1 parent de6efe1 commit e244745

File tree

18 files changed

+270
-27
lines changed

18 files changed

+270
-27
lines changed

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,14 @@ resource "aws_instance" "docker_instance" {
10931093
vpc_security_group_ids = [aws_security_group.instance_sg.id]
10941094
key_name = aws_key_pair.deployer.key_name
10951095
1096+
# prevent accidental termination of ec2 instance and data loss
1097+
# if you will need to recreate the instance still (not sure why it can be?), you will need to remove this block manually by next command:
1098+
# > terraform taint aws_instance.app_instance
1099+
lifecycle {
1100+
prevent_destroy = true
1101+
ignore_changes = [ami]
1102+
}
1103+
10961104
user_data = <<-EOF
10971105
#!/bin/bash
10981106
yum update -y

adminforth/documentation/blog/2024-10-31-compose-ec2-deployment/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,21 @@ resource "aws_instance" "myadmin_instance" {
150150
vpc_security_group_ids = [aws_security_group.instance_sg.id]
151151
key_name = aws_key_pair.myadmin_deploy_key.key_name
152152
153+
# prevent accidental termination of ec2 instance and data loss
154+
# if you will need to recreate the instance still (not sure why it can be?), you will need to remove this block manually by next command:
155+
# > terraform taint aws_instance.app_instance
156+
lifecycle {
157+
prevent_destroy = true
158+
ignore_changes = [ami]
159+
}
160+
161+
153162
root_block_device {
154163
volume_size = 20 // Size in GB for root partition
155164
volume_type = "gp2"
165+
166+
# Even if the instance is terminated, the volume will not be deleted, delete it manually if needed
167+
delete_on_termination = false
156168
}
157169
158170
user_data = <<-EOF

adminforth/documentation/blog/2024-11-14-compose-ec2-deployment-ci/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,20 @@ resource "aws_instance" "app_instance" {
192192
vpc_security_group_ids = [aws_security_group.instance_sg.id]
193193
key_name = aws_key_pair.app_deployer.key_name
194194
195+
# prevent accidental termination of ec2 instance and data loss
196+
# if you will need to recreate the instance still (not sure why it can be?), you will need to remove this block manually by next command:
197+
# > terraform taint aws_instance.app_instance
198+
lifecycle {
199+
prevent_destroy = true
200+
ignore_changes = [ami]
201+
}
202+
195203
root_block_device {
196204
volume_size = 20 // Size in GB for root partition
197205
volume_type = "gp2"
206+
207+
# Even if the instance is terminated, the volume will not be deleted, delete it manually if needed
208+
delete_on_termination = false
198209
}
199210
200211
user_data = <<-EOF

adminforth/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adminforth",
3-
"version": "1.5.7",
3+
"version": "1.5.8-next.0",
44
"description": "OpenSource Vue3 powered forth-generation admin panel",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

adminforth/plugins/i18n/custom/LanguageUnderLogin.vue

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,76 @@
11
<template>
2-
<p class="text-gray-500 dark:text-gray-400 font-sm text-left mt-3">
2+
<p class="text-gray-500 dark:text-gray-400 font-sm text-left mt-3 flex items-center justify-center">
33
<Select
44
v-model="selectedLanguage"
55
:options="options"
66
:placeholder="$t('Select language')"
77
@change="changeLanguage"
88
>
99
<template #item="{ option }">
10-
<span>{{ option.name }}</span>
10+
<span class="mr-1">
11+
<span class="flag-icon"
12+
:class="`flag-icon-${getCountryCodeFromLangCode(option.value)}`"
13+
></span>
14+
15+
</span>
16+
<span>{{ option.label }}</span>
17+
</template>
18+
19+
<template #selected-item="{option}">
20+
<span class="mr-1">
21+
<span class="flag-icon"
22+
:class="`flag-icon-${getCountryCodeFromLangCode(option.value)}`"
23+
></span>
24+
</span>
25+
<span>{{ option.label }}</span>
1126
</template>
1227
</Select>
1328
</p>
1429
</template>
1530

1631
<script setup>
1732
import Select from '@/afcl/Select.vue';
18-
import { computed, ref, onMounted } from 'vue';
33+
import 'flag-icon-css/css/flag-icons.min.css';
34+
import { setLang } from './langCommon';
35+
36+
import { computed, ref, onMounted, watch } from 'vue';
37+
import { useI18n } from 'vue-i18n';
38+
39+
const { setLocaleMessage, locale } = useI18n();
40+
1941
2042
const props = defineProps(['meta', 'resource']);
2143
2244
const selectedLanguage = ref('');
2345
46+
47+
48+
watch(() => selectedLanguage.value, (newVal) => {
49+
localStorage.setItem(LS_LANG_KEY, newVal);
50+
51+
52+
53+
setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, newVal);
54+
});
55+
56+
57+
// only remap the country code for the languages where language code is different from the country code
58+
// don't include es: es, fr: fr, etc, only include the ones where language code is different from the country code
59+
const countryISO31661ByLangISO6391 = {
60+
en: 'us', // English → United States
61+
zh: 'cn', // Chinese → China
62+
hi: 'in', // Hindi → India
63+
ar: 'sa', // Arabic → Saudi Arabia
64+
ko: 'kr', // Korean → South Korea
65+
ja: 'jp', // Japanese → Japan
66+
uk: 'ua', // Ukrainian → Ukraine
67+
};
68+
69+
function getCountryCodeFromLangCode(langCode) {
70+
return countryISO31661ByLangISO6391[langCode] || langCode;
71+
}
72+
73+
2474
const options = computed(() => {
2575
return props.meta.supportedLanguages.map((lang) => {
2676
return {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import { callAdminForthApi } from '@/utils';
3+
4+
5+
const messagesCache: Record<
6+
string,
7+
{
8+
ts: number;
9+
messages: Record<string, string>;
10+
}
11+
> = {};
12+
13+
// cleanup messages after a 2 minutes (cache for instant switching)
14+
setInterval(() => {
15+
const now = Date.now();
16+
for (const lang in messagesCache) {
17+
if (now - messagesCache[lang].ts > 10 * 60 * 1000) {
18+
delete messagesCache[lang];
19+
}
20+
}
21+
}, 60 * 1000);
22+
23+
// i18n is vue-i18n instance
24+
export async function setLang({ setLocaleMessage, locale }: any, pluginInstanceId: string, langIso: string) {
25+
26+
27+
if (!messagesCache[langIso]) {
28+
const messages = await callAdminForthApi({
29+
path: `/plugin/${pluginInstanceId}/frontend_messages?lang=${langIso}`,
30+
method: 'GET',
31+
});
32+
messagesCache[langIso] = {
33+
ts: Date.now(),
34+
messages: messages
35+
};
36+
}
37+
38+
// set locale and locale message
39+
setLocaleMessage(langIso, messagesCache[langIso].messages);
40+
41+
// set the language
42+
locale.value = langIso;
43+
44+
document.querySelector('html').setAttribute('lang', langIso);
45+
}

adminforth/plugins/i18n/custom/package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "custom",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"description": "",
12+
"devDependencies": {
13+
"flag-icon-css": "^4.1.7"
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".", // This should point to your project root
4+
"paths": {
5+
"@/*": [
6+
// "node_modules/adminforth/dist/spa/src/*"
7+
"../../../spa/src/*"
8+
],
9+
"*": [
10+
// "node_modules/adminforth/dist/spa/node_modules/*"
11+
"../../../spa/node_modules/*"
12+
],
13+
"@@/*": [
14+
// "node_modules/adminforth/dist/spa/src/*"
15+
"."
16+
]
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)