@adminforth/i18n 1.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.woodpecker/buildRelease.sh +13 -0
- package/.woodpecker/buildSlackNotify.sh +42 -0
- package/.woodpecker/release.yml +45 -0
- package/Changelog.md +71 -0
- package/LICENSE +21 -0
- package/build.log +15 -0
- package/custom/LanguageInUserMenu.vue +102 -0
- package/custom/LanguageUnderLogin.vue +76 -0
- package/custom/langCommon.ts +89 -0
- package/custom/package-lock.json +24 -0
- package/custom/package.json +15 -0
- package/custom/tsconfig.json +19 -0
- package/dist/custom/LanguageInUserMenu.vue +102 -0
- package/dist/custom/LanguageUnderLogin.vue +76 -0
- package/dist/custom/langCommon.ts +89 -0
- package/dist/custom/package-lock.json +24 -0
- package/dist/custom/package.json +15 -0
- package/dist/custom/tsconfig.json +19 -0
- package/dist/index.js +749 -0
- package/dist/types.js +1 -0
- package/index.ts +889 -0
- package/package.json +54 -0
- package/tsconfig.json +12 -0
- package/types.ts +39 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
#!/bin/bash
|
|
3
|
+
|
|
4
|
+
# write npm run output both to console and to build.log
|
|
5
|
+
npm run build 2>&1 | tee build.log
|
|
6
|
+
build_status=${PIPESTATUS[0]}
|
|
7
|
+
|
|
8
|
+
# if exist status from the npm run build is not 0
|
|
9
|
+
# then exit with the status code from the npm run build
|
|
10
|
+
if [ $build_status -ne 0 ]; then
|
|
11
|
+
echo "Build failed. Exiting with status code $build_status"
|
|
12
|
+
exit $build_status
|
|
13
|
+
fi
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
COMMIT_SHORT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if [ "$CI_STEP_STATUS" = "success" ]; then
|
|
8
|
+
MESSAGE="Did a build without issues on \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\`. Commit: _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
|
|
9
|
+
|
|
10
|
+
curl -s -X POST -H "Content-Type: application/json" -d '{
|
|
11
|
+
"username": "'"$CI_COMMIT_AUTHOR"'",
|
|
12
|
+
"icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
|
|
13
|
+
"attachments": [
|
|
14
|
+
{
|
|
15
|
+
"mrkdwn_in": ["text", "pretext"],
|
|
16
|
+
"color": "#36a64f",
|
|
17
|
+
"text": "'"$MESSAGE"'"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}' "$DEVELOPERS_SLACK_WEBHOOK"
|
|
21
|
+
exit 0
|
|
22
|
+
fi
|
|
23
|
+
export BUILD_LOG=$(cat ./build.log)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
MESSAGE="Broke \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\` with commit _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
|
|
27
|
+
CODE_BLOCK="\`\`\`$BUILD_LOG\n\`\`\`"
|
|
28
|
+
|
|
29
|
+
echo "Sending slack message to developers $MESSAGE"
|
|
30
|
+
# Send the message
|
|
31
|
+
curl -X POST -H "Content-Type: application/json" -d '{
|
|
32
|
+
"username": "'"$CI_COMMIT_AUTHOR"'",
|
|
33
|
+
"icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
|
|
34
|
+
"attachments": [
|
|
35
|
+
{
|
|
36
|
+
"mrkdwn_in": ["text", "pretext"],
|
|
37
|
+
"color": "#8A1C12",
|
|
38
|
+
"text": "'"$CODE_BLOCK"'",
|
|
39
|
+
"pretext": "'"$MESSAGE"'"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}' "$DEVELOPERS_SLACK_WEBHOOK"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
clone:
|
|
2
|
+
git:
|
|
3
|
+
image: woodpeckerci/plugin-git
|
|
4
|
+
settings:
|
|
5
|
+
partial: false
|
|
6
|
+
depth: 5
|
|
7
|
+
|
|
8
|
+
steps:
|
|
9
|
+
init-secrets:
|
|
10
|
+
when:
|
|
11
|
+
- event: push
|
|
12
|
+
image: infisical/cli
|
|
13
|
+
environment:
|
|
14
|
+
INFISICAL_TOKEN:
|
|
15
|
+
from_secret: VAULT_TOKEN
|
|
16
|
+
commands:
|
|
17
|
+
- infisical export --domain https://vault.devforth.io/api --format=dotenv-export --env="prod" > /woodpecker/deploy.vault.env
|
|
18
|
+
secrets:
|
|
19
|
+
- VAULT_TOKEN
|
|
20
|
+
|
|
21
|
+
release:
|
|
22
|
+
image: node:20
|
|
23
|
+
when:
|
|
24
|
+
- event: push
|
|
25
|
+
volumes:
|
|
26
|
+
- /var/run/docker.sock:/var/run/docker.sock
|
|
27
|
+
commands:
|
|
28
|
+
# install rsync
|
|
29
|
+
- apt update && apt install -y rsync
|
|
30
|
+
- export $(cat /woodpecker/deploy.vault.env | xargs)
|
|
31
|
+
- npm clean-install
|
|
32
|
+
- /bin/bash ./.woodpecker/buildRelease.sh
|
|
33
|
+
- npm audit signatures
|
|
34
|
+
- npx semantic-release
|
|
35
|
+
|
|
36
|
+
slack-on-failure:
|
|
37
|
+
when:
|
|
38
|
+
- event: push
|
|
39
|
+
status: [failure, success]
|
|
40
|
+
- event: push
|
|
41
|
+
image: curlimages/curl
|
|
42
|
+
commands:
|
|
43
|
+
- export $(cat /woodpecker/deploy.vault.env | xargs)
|
|
44
|
+
- /bin/sh ./.woodpecker/buildSlackNotify.sh
|
|
45
|
+
|
package/Changelog.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.23] - next
|
|
9
|
+
|
|
10
|
+
### Improved
|
|
11
|
+
|
|
12
|
+
- Better instructions for LLM pluralization Slavik messages
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- support for pluralization in Backend `tr` function
|
|
16
|
+
- add handy languagesList function to get all languages for translation of side apps
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- invalidation of indvidual tr messages when translation using LLM adapter
|
|
20
|
+
|
|
21
|
+
## [1.0.22]
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- More predictable class name
|
|
26
|
+
- When loading unique translations from category, they were not registered if existing in other category
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## [1.0.21] - 2024-12-30
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
- improve cache reset when editing messages manually
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
- Translating external app" feature by using feedCategoryTranslations
|
|
36
|
+
|
|
37
|
+
## [1.0.20]
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
- fix automatic translations
|
|
41
|
+
|
|
42
|
+
## [1.0.14]
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- Add `ignoreInitial` for watch to prevent initial messages loading
|
|
47
|
+
- Add locking mechanism to prevent initial messages loading call in parallel (just in case)
|
|
48
|
+
|
|
49
|
+
## [1.0.13]
|
|
50
|
+
|
|
51
|
+
- Deduplicate frontend strings before creating translations
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## [1.0.12]
|
|
55
|
+
|
|
56
|
+
### Fixed
|
|
57
|
+
|
|
58
|
+
- live mode frontend translations loading when tmp dir is nopt preserver (e.g. docker cached /tmp pipeline)
|
|
59
|
+
|
|
60
|
+
## [1.0.11]
|
|
61
|
+
|
|
62
|
+
### Fixed
|
|
63
|
+
|
|
64
|
+
- cache invalidations on delete
|
|
65
|
+
|
|
66
|
+
## [v1.0.10]
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
- fix automatic translations for duplicate strings
|
|
71
|
+
- improve slavik pluralization generations by splitting the requests
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Devforth.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build.log
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
> @adminforth/i18n@1.0.23-next.3 build
|
|
3
|
+
> tsc && rsync -av --exclude 'node_modules' custom dist/
|
|
4
|
+
|
|
5
|
+
sending incremental file list
|
|
6
|
+
custom/
|
|
7
|
+
custom/LanguageInUserMenu.vue
|
|
8
|
+
custom/LanguageUnderLogin.vue
|
|
9
|
+
custom/langCommon.ts
|
|
10
|
+
custom/package-lock.json
|
|
11
|
+
custom/package.json
|
|
12
|
+
custom/tsconfig.json
|
|
13
|
+
|
|
14
|
+
sent 9,620 bytes received 134 bytes 19,508.00 bytes/sec
|
|
15
|
+
total size is 9,122 speedup is 0.94
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="min-w-40">
|
|
3
|
+
<div class="cursor-pointer flex items-center gap-1 block px-4 py-2 text-sm text-black
|
|
4
|
+
hover:bg-html dark:text-darkSidebarTextHover dark:hover:bg-darkSidebarItemHover dark:hover:text-darkSidebarTextActive
|
|
5
|
+
w-full select-none "
|
|
6
|
+
:class="{ 'bg-black bg-opacity-10 ': showDropdown }"
|
|
7
|
+
@click="showDropdown = !showDropdown"
|
|
8
|
+
>
|
|
9
|
+
<span class="mr-1">
|
|
10
|
+
<span class="flag-icon"
|
|
11
|
+
:class="`flag-icon-${getCountryCodeFromLangCode(selectedOption.value)}`"
|
|
12
|
+
></span>
|
|
13
|
+
</span>
|
|
14
|
+
<span>{{ selectedOption.label }}</span>
|
|
15
|
+
|
|
16
|
+
<IconCaretDownSolid class="h-5 w-5 text-lightPrimary dark:text-gray-400 opacity-50 transition duration-150 ease-in"
|
|
17
|
+
:class="{ 'transform rotate-180': showDropdown }"
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div v-if="showDropdown" >
|
|
22
|
+
|
|
23
|
+
<div class="cursor-pointer flex items-center gap-1 block px-4 py-1 text-sm
|
|
24
|
+
text-black dark:text-darkSidebarTextHover
|
|
25
|
+
bg-black bg-opacity-10
|
|
26
|
+
hover:brightness-110
|
|
27
|
+
hover:text-lightPrimary dark:hover:text-darkPrimary
|
|
28
|
+
hover:bg-lightPrimaryContrast dark:hover:bg-darkPrimaryContrast
|
|
29
|
+
w-full text-select-none pl-5 select-none"
|
|
30
|
+
v-for="option in options.filter((opt) => opt.value !== selectedOption.value)"
|
|
31
|
+
@click="doChangeLang(option.value)"
|
|
32
|
+
>
|
|
33
|
+
<span class="mr-1">
|
|
34
|
+
<span class="flag-icon"
|
|
35
|
+
:class="`flag-icon-${getCountryCodeFromLangCode(option.value)}`"
|
|
36
|
+
></span>
|
|
37
|
+
</span>
|
|
38
|
+
<span>{{ option.label }}</span>
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script setup>
|
|
48
|
+
import 'flag-icon-css/css/flag-icons.min.css';
|
|
49
|
+
import { IconCaretDownSolid } from '@iconify-prerendered/vue-flowbite';
|
|
50
|
+
|
|
51
|
+
import { setLang, getCountryCodeFromLangCode, getLocalLang, setLocalLang } from './langCommon';
|
|
52
|
+
|
|
53
|
+
import { computed, ref, onMounted, watch } from 'vue';
|
|
54
|
+
import { useI18n } from 'vue-i18n';
|
|
55
|
+
|
|
56
|
+
const { setLocaleMessage, locale } = useI18n();
|
|
57
|
+
|
|
58
|
+
const showDropdown = ref(false);
|
|
59
|
+
const props = defineProps(['meta', 'resource']);
|
|
60
|
+
|
|
61
|
+
const selectedLanguage = ref('');
|
|
62
|
+
|
|
63
|
+
function doChangeLang(lang) {
|
|
64
|
+
setLocalLang(lang);
|
|
65
|
+
// unfortunately, we need this to recall all APIs
|
|
66
|
+
document.location.reload();
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const options = computed(() => {
|
|
72
|
+
return props.meta.supportedLanguages.map((lang) => {
|
|
73
|
+
return {
|
|
74
|
+
value: lang.code,
|
|
75
|
+
label: lang.name,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const selectedOption = computed(() => {
|
|
81
|
+
const val = options.value.find((option) => option.value === selectedLanguage.value);
|
|
82
|
+
if (val) {
|
|
83
|
+
return val;
|
|
84
|
+
}
|
|
85
|
+
return options.value[0];
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
onMounted(() => {
|
|
90
|
+
console.log('Language In user menu mounted', props.meta.supportedLanguages);
|
|
91
|
+
selectedLanguage.value = getLocalLang(props.meta.supportedLanguages);
|
|
92
|
+
setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, selectedLanguage.value);
|
|
93
|
+
// todo this mounted executed only on this component mount, f5 from another page apart login will not read it
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
</script>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<p class="text-gray-500 dark:text-gray-400 font-sm text-left mt-3 flex items-center justify-center">
|
|
3
|
+
<Select
|
|
4
|
+
class="w-full"
|
|
5
|
+
v-model="selectedLanguage"
|
|
6
|
+
:options="options"
|
|
7
|
+
:placeholder="$t('Select language')"
|
|
8
|
+
>
|
|
9
|
+
<template #item="{ option }">
|
|
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>
|
|
26
|
+
</template>
|
|
27
|
+
</Select>
|
|
28
|
+
</p>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script setup>
|
|
32
|
+
import Select from '@/afcl/Select.vue';
|
|
33
|
+
import 'flag-icon-css/css/flag-icons.min.css';
|
|
34
|
+
import { setLang, getCountryCodeFromLangCode, getLocalLang } from './langCommon';
|
|
35
|
+
import { useCoreStore } from '@/stores/core';
|
|
36
|
+
|
|
37
|
+
import { computed, ref, onMounted, watch } from 'vue';
|
|
38
|
+
import { useI18n } from 'vue-i18n';
|
|
39
|
+
|
|
40
|
+
const { setLocaleMessage, locale } = useI18n();
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const props = defineProps(['meta', 'resource']);
|
|
44
|
+
|
|
45
|
+
const selectedLanguage = ref('');
|
|
46
|
+
const coreStore = useCoreStore();
|
|
47
|
+
|
|
48
|
+
watch(() => selectedLanguage.value, async (newVal) => {
|
|
49
|
+
await setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, newVal);
|
|
50
|
+
coreStore.getPublicConfig();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const options = computed(() => {
|
|
55
|
+
return props.meta.supportedLanguages.map((lang) => {
|
|
56
|
+
return {
|
|
57
|
+
value: lang.code,
|
|
58
|
+
label: lang.name,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
onMounted(() => {
|
|
64
|
+
console.log('LanguageUnderLogin mounted', props.meta.supportedLanguages);
|
|
65
|
+
selectedLanguage.value = getLocalLang(props.meta.supportedLanguages);
|
|
66
|
+
setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, selectedLanguage.value);
|
|
67
|
+
// todo this mounted executed only on this component mount, f5 from another page apart login will not read it
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
</script>
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
if (!messagesCache[langIso]) {
|
|
27
|
+
const messages = await callAdminForthApi({
|
|
28
|
+
path: `/plugin/${pluginInstanceId}/frontend_messages?lang=${langIso}`,
|
|
29
|
+
method: 'GET',
|
|
30
|
+
});
|
|
31
|
+
messagesCache[langIso] = {
|
|
32
|
+
ts: Date.now(),
|
|
33
|
+
messages: messages
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// set locale and locale message
|
|
38
|
+
setLocaleMessage(langIso, messagesCache[langIso].messages);
|
|
39
|
+
|
|
40
|
+
// set the language
|
|
41
|
+
locale.value = langIso;
|
|
42
|
+
|
|
43
|
+
document.querySelector('html').setAttribute('lang', langIso);
|
|
44
|
+
setLocalLang(langIso);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// only remap the country code for the languages where language code is different from the country code
|
|
48
|
+
// don't include es: es, fr: fr, etc, only include the ones where language code is different from the country code
|
|
49
|
+
const countryISO31661ByLangISO6391 = {
|
|
50
|
+
en: 'us', // English → United States
|
|
51
|
+
zh: 'cn', // Chinese → China
|
|
52
|
+
hi: 'in', // Hindi → India
|
|
53
|
+
ar: 'sa', // Arabic → Saudi Arabia
|
|
54
|
+
ko: 'kr', // Korean → South Korea
|
|
55
|
+
ja: 'jp', // Japanese → Japan
|
|
56
|
+
uk: 'ua', // Ukrainian → Ukraine
|
|
57
|
+
ur: 'pk', // Urdu → Pakistan
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function getCountryCodeFromLangCode(langCode) {
|
|
61
|
+
return countryISO31661ByLangISO6391[langCode] || langCode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const LS_LANG_KEY = `afLanguage`;
|
|
66
|
+
|
|
67
|
+
export function getLocalLang(supportedLanguages: {code}[]): string {
|
|
68
|
+
let lsLang = localStorage.getItem(LS_LANG_KEY);
|
|
69
|
+
// if someone screwed up the local storage or we stopped language support, lets check if it is in supported languages
|
|
70
|
+
if (lsLang && !supportedLanguages.find((l) => l.code == lsLang)) {
|
|
71
|
+
lsLang = null;
|
|
72
|
+
}
|
|
73
|
+
if (lsLang) {
|
|
74
|
+
return lsLang;
|
|
75
|
+
}
|
|
76
|
+
// read lang from navigator and try find what we have in supported languages
|
|
77
|
+
const lang = navigator.language.split('-')[0];
|
|
78
|
+
const foundLang = supportedLanguages.find((l) => l.code == lang);
|
|
79
|
+
if (foundLang) {
|
|
80
|
+
return foundLang.code;
|
|
81
|
+
}
|
|
82
|
+
return supportedLanguages[0].code;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function setLocalLang(lang: string) {
|
|
86
|
+
localStorage.setItem(LS_LANG_KEY, lang);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "custom",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "custom",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"flag-icon-css": "^4.1.7"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"node_modules/flag-icon-css": {
|
|
16
|
+
"version": "4.1.7",
|
|
17
|
+
"resolved": "https://registry.npmjs.org/flag-icon-css/-/flag-icon-css-4.1.7.tgz",
|
|
18
|
+
"integrity": "sha512-AFjSU+fv98XbU0vnTQ32vcLj89UEr1MhwDFcooQv14qWJCjg9fGZzfh9BVyDhAhIOZW/pGmJmq38RqpgPaeybQ==",
|
|
19
|
+
"deprecated": "The project has been renamed to flag-icons",
|
|
20
|
+
"dev": true,
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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,0 +1,102 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="min-w-40">
|
|
3
|
+
<div class="cursor-pointer flex items-center gap-1 block px-4 py-2 text-sm text-black
|
|
4
|
+
hover:bg-html dark:text-darkSidebarTextHover dark:hover:bg-darkSidebarItemHover dark:hover:text-darkSidebarTextActive
|
|
5
|
+
w-full select-none "
|
|
6
|
+
:class="{ 'bg-black bg-opacity-10 ': showDropdown }"
|
|
7
|
+
@click="showDropdown = !showDropdown"
|
|
8
|
+
>
|
|
9
|
+
<span class="mr-1">
|
|
10
|
+
<span class="flag-icon"
|
|
11
|
+
:class="`flag-icon-${getCountryCodeFromLangCode(selectedOption.value)}`"
|
|
12
|
+
></span>
|
|
13
|
+
</span>
|
|
14
|
+
<span>{{ selectedOption.label }}</span>
|
|
15
|
+
|
|
16
|
+
<IconCaretDownSolid class="h-5 w-5 text-lightPrimary dark:text-gray-400 opacity-50 transition duration-150 ease-in"
|
|
17
|
+
:class="{ 'transform rotate-180': showDropdown }"
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div v-if="showDropdown" >
|
|
22
|
+
|
|
23
|
+
<div class="cursor-pointer flex items-center gap-1 block px-4 py-1 text-sm
|
|
24
|
+
text-black dark:text-darkSidebarTextHover
|
|
25
|
+
bg-black bg-opacity-10
|
|
26
|
+
hover:brightness-110
|
|
27
|
+
hover:text-lightPrimary dark:hover:text-darkPrimary
|
|
28
|
+
hover:bg-lightPrimaryContrast dark:hover:bg-darkPrimaryContrast
|
|
29
|
+
w-full text-select-none pl-5 select-none"
|
|
30
|
+
v-for="option in options.filter((opt) => opt.value !== selectedOption.value)"
|
|
31
|
+
@click="doChangeLang(option.value)"
|
|
32
|
+
>
|
|
33
|
+
<span class="mr-1">
|
|
34
|
+
<span class="flag-icon"
|
|
35
|
+
:class="`flag-icon-${getCountryCodeFromLangCode(option.value)}`"
|
|
36
|
+
></span>
|
|
37
|
+
</span>
|
|
38
|
+
<span>{{ option.label }}</span>
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script setup>
|
|
48
|
+
import 'flag-icon-css/css/flag-icons.min.css';
|
|
49
|
+
import { IconCaretDownSolid } from '@iconify-prerendered/vue-flowbite';
|
|
50
|
+
|
|
51
|
+
import { setLang, getCountryCodeFromLangCode, getLocalLang, setLocalLang } from './langCommon';
|
|
52
|
+
|
|
53
|
+
import { computed, ref, onMounted, watch } from 'vue';
|
|
54
|
+
import { useI18n } from 'vue-i18n';
|
|
55
|
+
|
|
56
|
+
const { setLocaleMessage, locale } = useI18n();
|
|
57
|
+
|
|
58
|
+
const showDropdown = ref(false);
|
|
59
|
+
const props = defineProps(['meta', 'resource']);
|
|
60
|
+
|
|
61
|
+
const selectedLanguage = ref('');
|
|
62
|
+
|
|
63
|
+
function doChangeLang(lang) {
|
|
64
|
+
setLocalLang(lang);
|
|
65
|
+
// unfortunately, we need this to recall all APIs
|
|
66
|
+
document.location.reload();
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const options = computed(() => {
|
|
72
|
+
return props.meta.supportedLanguages.map((lang) => {
|
|
73
|
+
return {
|
|
74
|
+
value: lang.code,
|
|
75
|
+
label: lang.name,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const selectedOption = computed(() => {
|
|
81
|
+
const val = options.value.find((option) => option.value === selectedLanguage.value);
|
|
82
|
+
if (val) {
|
|
83
|
+
return val;
|
|
84
|
+
}
|
|
85
|
+
return options.value[0];
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
onMounted(() => {
|
|
90
|
+
console.log('Language In user menu mounted', props.meta.supportedLanguages);
|
|
91
|
+
selectedLanguage.value = getLocalLang(props.meta.supportedLanguages);
|
|
92
|
+
setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, selectedLanguage.value);
|
|
93
|
+
// todo this mounted executed only on this component mount, f5 from another page apart login will not read it
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
</script>
|