diff --git a/resource/js/term-counts.js b/resource/js/term-counts.js
index c53cefe3f..08e099d02 100644
--- a/resource/js/term-counts.js
+++ b/resource/js/term-counts.js
@@ -1,51 +1,64 @@
/* global Vue */
-const termCountsApp = Vue.createApp({
- data () {
- return {
- languages: []
- }
- },
- mounted () {
- fetch('rest/v1/' + window.SKOSMOS.vocab + '/labelStatistics?lang=' + window.SKOSMOS.lang)
- .then(data => {
- return data.json()
- })
- .then(data => {
- this.languages = data.languages
- })
- },
- template: `
-
Term counts by language
-
-
-
- Concept language |
- Preferred terms |
- Alternate terms |
- Hidden terms |
+import { createI18nInstance } from './translation-service.js';
+
+(async function () {
+
+ try {
+ const i18n = await createI18nInstance(window.SKOSMOS.lang || 'fi', 'term-counts');
+
+ const termCountsApp = Vue.createApp({
+ data() {
+ return {
+ languages: []
+ };
+ },
+ mounted () {
+ fetch('rest/v1/' + window.SKOSMOS.vocab + '/labelStatistics?lang=' + window.SKOSMOS.lang)
+ .then(data => {
+ return data.json()
+ })
+ .then(data => {
+ this.languages = data.languages
+ })
+ },
+ template: `
+ {{ $t('Term counts by language') }}
+
+
+
+ {{ $t('Concept language') }} |
+ {{ $t('Preferred terms') }} |
+ {{ $t('Alternate terms') }} |
+ {{ $t('Hidden terms') }} |
+
+
+
+
+
+
+
+
+
+ `
+ });
+
+ termCountsApp.component('term-counts', {
+ props: ['languages'],
+ template: `
+
+ {{ l.literal }} |
+ {{ l.properties.find(a => a.property === 'skos:prefLabel').labels }} |
+ {{ l.properties.find(a => a.property === 'skos:altLabel').labels }} |
+ {{ l.properties.find(a => a.property === 'skos:hiddenLabel').labels }} |
-
-
-
-
-
-
-
-
- `
-})
+ `
+ });
-termCountsApp.component('term-counts', {
- props: ['languages'],
- template: `
-
- {{ l.literal }} |
- {{ l.properties.find(a => a.property === 'skos:prefLabel').labels }} |
- {{ l.properties.find(a => a.property === 'skos:altLabel').labels }} |
- {{ l.properties.find(a => a.property === 'skos:hiddenLabel').labels }} |
-
- `
-})
+ termCountsApp.use(i18n);
+ termCountsApp.mount('#term-counts');
-termCountsApp.mount('#term-counts')
+ } catch (error) {
+ console.error("Ongelma alustuksessa", error);
+ }
+})();
diff --git a/resource/js/translation-service.js b/resource/js/translation-service.js
new file mode 100644
index 000000000..2e386e3c9
--- /dev/null
+++ b/resource/js/translation-service.js
@@ -0,0 +1,24 @@
+export async function loadLocaleMessages(locale) {
+ const messages = {};
+ try {
+ const response = await fetch(`http://localhost/skosmos/resource/translations/messages.${locale}.json`);
+ const data = await response.json();
+ console.log(`Haettiin data: ${locale}:`, data);
+ messages[locale] = data;
+ } catch (error) {
+ console.error('käännösten lataamisessa tapahtui virhe:', error);
+ }
+ return messages;
+}
+
+export async function createI18nInstance(locale = 'en', componentName = 'Unknown Component') {
+ const messages = await loadLocaleMessages(locale);
+ const i18n = VueI18n.createI18n({
+ locale: locale,
+ fallbackLocale: 'en', // fallback-kieli
+ messages
+ });
+
+ console.log('Luotiin i18n:', i18n);
+ return i18n;
+}
diff --git a/resource/js/vocab-counts.js b/resource/js/vocab-counts.js
index ca62fd278..086b19d80 100644
--- a/resource/js/vocab-counts.js
+++ b/resource/js/vocab-counts.js
@@ -1,32 +1,10 @@
-async function loadLocaleMessages() {
- const lang = 'fi'; // Myöhemmin käytetään globaalia muuttujaa
- const messages = {};
+import { createI18nInstance } from './translation-service.js';
- const response = await fetch(`http://localhost/skosmos/resource/translations/messages.${lang}.json`);
- const data = await response.json();
- console.log(data);
- messages[lang] = data;
-
- return messages;
-}
-
-async function createI18nInstance() {
- const messages = await loadLocaleMessages();
-
- const i18n = VueI18n.createI18n({
- locale: window.SKOSMOS.lang || 'en', // oletus
- fallbackLocale: 'en', // fallback
- messages,
- });
-
- return i18n;
-}
-
-(async function() {
- const i18n = await createI18nInstance();
+(async function () {
+ const i18n = await createI18nInstance(window.SKOSMOS.lang || 'fi', 'vocab-counts');
const resourceCountsApp = Vue.createApp({
- data() {
+ data () {
return {
concepts: {},
subTypes: {},
@@ -34,11 +12,11 @@ async function createI18nInstance() {
};
},
computed: {
- hasCounts() {
+ hasCounts () {
return Object.keys(this.concepts).length > 0;
}
},
- mounted() {
+ mounted () {
fetch('rest/v1/' + window.SKOSMOS.vocab + '/vocabularyStatistics?lang=' + window.SKOSMOS.lang)
.then(data => data.json())
.then(data => {
@@ -46,7 +24,7 @@ async function createI18nInstance() {
this.subTypes = data.subTypes;
this.conceptGroups = data.conceptGroups;
});
- },
+ },
template: `
{{ $t('Resource counts by type') }}
@@ -55,7 +33,7 @@ async function createI18nInstance() {
-
+
@@ -70,7 +48,7 @@ async function createI18nInstance() {
{{ concepts.label }} |
{{ concepts.count }} |
-
+
* {{ st.label }} |
{{ st.count }} |
diff --git a/src/view/scripts.inc.twig b/src/view/scripts.inc.twig
index 717ea82e5..2fc210d37 100644
--- a/src/view/scripts.inc.twig
+++ b/src/view/scripts.inc.twig
@@ -94,8 +94,8 @@ window.SKOSMOS = {
-
-
+
+