Skip to content

Commit

Permalink
Async loading for languages, translate bootstrap and sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Dec 21, 2022
1 parent 861139e commit 11d09ac
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 44 deletions.
8 changes: 5 additions & 3 deletions src/StacBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<router-view />
</main>
<footer>
<small class="poweredby text-muted">
{{ $t('poweredBy') }} <a href="https://github.com/radiantearth/stac-browser">STAC Browser</a> {{ browserVersion }}
</small>
<i18n tag="small" path="poweredBy" class="poweredby text-muted">
<template #link>
<a href="https://github.com/radiantearth/stac-browser" target="_blank">STAC Browser</a> {{ browserVersion }}
</template>
</i18n>
</footer>
</b-container>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export default {
fullscreenOptions() {
return {
title: {
'false': this.$t('leaflet.fullscreen.false'),
'true': this.$t('leaflet.fullscreen.true'),
'false': this.$t('fullscreen.show'),
'true': this.$t('fullscreen.exit'),
}
};
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<Loading v-if="!parents" />
<Tree v-else-if="root" :item="root" :path="parents" />

<b-button v-if="allowSelectCatalog" class="switch-catalog mt-4" variant="light"><router-link to="/"><b-icon-arrow-left-right /> Switch Catalog</router-link></b-button>
<b-button v-if="allowSelectCatalog" class="switch-catalog mt-4" variant="light">
<router-link to="/"><b-icon-arrow-left-right /> {{$t('sidebar.switchCatalog') }}</router-link>
</b-button>
</div>
</template>

Expand Down
8 changes: 3 additions & 5 deletions src/components/Source.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<template #button-content>
<b-icon-flag /> <span class="button-label">Language ({{ currentLanguage }})</span>
</template>
<b-dropdown-item v-for="l of supportedLocales" :key="l" @click="switchLanguage(l)">
<b-dropdown-item v-for="l of supportedLocales" :key="l" @click="switchLocale(l)">
<b-icon-check v-if="locale === l" />
<b-icon-blank v-else />
{{ $t(`languages.${l}.native`) }} / {{ $t(`languages.${l}.global`) }}
Expand Down Expand Up @@ -57,7 +57,7 @@
import {
BIconBlank, BIconCheck, BIconEnvelope, BIconFlag, BIconLink, BIconShare, BIconTwitter,
BDropdown, BDropdownItem, BPopover } from 'bootstrap-vue';
import { mapState } from 'vuex';
import { mapActions, mapState } from 'vuex';
import Url from './Url.vue';
Expand Down Expand Up @@ -132,14 +132,12 @@ export default {
}
},
methods: {
...mapActions(['switchLocale']),
async validate() {
await this.$store.dispatch('validate', this.stacUrl);
},
browserUrl() {
return window.location.toString();
},
switchLanguage(locale) {
this.$store.commit('config', {locale});
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

<template v-if="expanded && mayHaveChildren">
<ul v-if="loading" class="tree">
<li><b-spinner label="Loading..." small /></li>
<li><b-spinner :label="$t('loading')" small /></li>
</ul>
<ul v-else-if="childs.length === 0" class="tree">
<li>
<b-button size="sm" variant="light" disabled>
No children available.
{{ $t('tree.noChildren') }}
</b-button>
</li>
</ul>
<template v-else>
<Tree v-for="(child, i) in shownChilds" :key="i" :item="child" :parent="stac" :path="path" />
<b-button class="show-more" v-if="hasMore" @click="showMore" variant="light" v-b-visible.200="showMore">Show more...</b-button>
<b-button class="show-more" v-if="hasMore" @click="showMore" variant="light" v-b-visible.200="showMore">{{ $t('tree.showMore') }}</b-button>
</template>
</template>
</li>
Expand Down Expand Up @@ -138,7 +138,7 @@ export default {
},
title() {
if (this.pagination) {
return 'more pages available for Collection';
return $t('moreCollectionPagesAvailable');
}
return STAC.getDisplayTitle([this.item, this.stac]);
},
Expand Down
10 changes: 10 additions & 0 deletions src/components/metadata/MetadataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class="metadata-table" :items="tblItems" :fields="tblFields" variant="light"
responsive small
sticky-header striped
v-bind="tblTexts"
>
<template #head()="data">
<span v-html="data.label" />
Expand All @@ -28,6 +29,15 @@ export default {
EntryMixin
],
computed: {
tblTexts() {
return {
'empty-filtered-text': this.$t('table.emptyFilteredText'),
'empty-text': this.$t('table.emptyText'),
'label-sort-asc': this.$t('table.sort.asc'),
'label-sort-desc': this.$t('table.sort.desc'),
'label-sort-clear': this.$t('table.sort.clear')
};
},
tblItems() {
if (Utils.isObject(this.value)) {
let items = [];
Expand Down
9 changes: 6 additions & 3 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ function loadLocaleMessages () {
const languages = {};
for(let locale of CONFIG.supportedLocales) {
languages[locale] = require(`./locales/${locale}/config.json`);
// ToDo: Load not yet required languages async
// https://kazupon.github.io/vue-i18n/guide/lazy-loading.html
messages[locale] = require(`./locales/${locale}/texts.json`);
if (CONFIG.locale == locale || CONFIG.fallbackLocale == locale) {
messages[locale] = require(`./locales/${locale}/texts.json`);
}
else {
messages[locale] = {};
}
}
for(let locale in messages) {
messages[locale].languages = languages;
Expand Down
49 changes: 41 additions & 8 deletions src/locales/de/texts.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
{
"poweredBy": "Generiert von",
"specifyCatalog": "Bitte gib einen STAC Catalog oder eine STAC API an...",
"selectStacIndex": "... oder wähle einen von STAC Index",
"load": "Laden",
"leaflet": {
"fullscreen": {
"false": "Zeige im Vollbild-Modus",
"true": "Verlasse den Vollbild-Modus"
"stacCollection": "Sammlung | Sammlungen",
"stacCatalog": "Katalog | Kataloge",
"stacItem": "Element | Elemente",
"poweredBy": "Generiert von {link}",
"loading": "Lade...",
"index": {
"specifyCatalog": "Bitte gib einen STAC Katalog oder eine STAC API an...",
"selectStacIndex": "... oder wähle von STAC Index:",
"load": "Laden",
"api": "API",
"catalog": "Katalog",
"urlMissingProtocol": "Der Adresse fehlt ein Protokoll.",
"urlMissingHost": "Der Adresse fehlt ein Host.",
"urlInvalid": "Die Adresse ist ungültig."
},
"fullscreen": {
"show": "Zeige im Vollbild-Modus",
"exit": "Verlasse den Vollbild-Modus"
},
"read": {
"less": "Zeige weniger",
"more": "Zeige mehr"
},
"tree": {
"showMore": "Zeige mehr...",
"noChildren": "Keine Unterpunkte verfügbar.",
"moreCollectionPagesAvailable": "Mehr Seiten für Sammlung verfügbar"
},
"sidebar": {
"switchCatalog": "Wechsle den Katalog"
},
"table": {
"emptyFilteredText": "Es gibt keine Einträge die dem Filter entsprechen",
"emptyText": "Keine Einträge verfügbar",
"sort": {
"asc": "Klicke um aufsteigend zu sortieren",
"desc": "Klicke um absteigend zu sortieren",
"clear": "Klicke um die Sortierung aufzuheben"
}
},
"fields": {

}
}
49 changes: 41 additions & 8 deletions src/locales/en/texts.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
{
"poweredBy": "Powered by",
"specifyCatalog": "Please specify a STAC Catalog or API...",
"selectStacIndex": "... or select one from STAC Index",
"load": "Load",
"leaflet": {
"fullscreen": {
"false": "View Fullscreen",
"true": "Exit Fullscreen"
"stacCollection": "Collection | Collections",
"stacCatalog": "Catalog | Catalogs",
"stacItem": "Item | Items",
"poweredBy": "Powered by {link}",
"loading": "Loading...",
"index": {
"specifyCatalog": "Please specify a STAC Catalog or API...",
"selectStacIndex": "... or select one from STAC Index:",
"load": "Load",
"api": "API",
"catalog": "Catalog",
"urlMissingProtocol": "The URL is missing a protocol.",
"urlMissingHost": "The URL is missing a host.",
"urlInvalid": "The URL is invalid."
},
"fullscreen": {
"show": "View Fullscreen",
"exit": "Exit Fullscreen"
},
"read": {
"less": "Read less",
"more": "Read more"
},
"tree": {
"showMore": "Show more...",
"noChildren": "No children available.",
"moreCollectionPagesAvailable": "more pages available for Collection"
},
"sidebar": {
"switchCatalog": "Switch Catalog"
},
"table": {
"emptyFilteredText": "There are no records matching your request",
"emptyText": "There are no records to show",
"sort": {
"asc": "Click to sort ascending",
"desc": "Click to sort descending",
"clear": "Click to clear sorting"
}
},
"fields": {

}
}
15 changes: 15 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { addQueryIfNotExists, isAuthenticationError, Loading, processSTAC, stacR
import { BrowserError } from '../utils';
import URI from "urijs";
import Queryable from '../models/queryable';
import i18n from '../i18n';

function getStore(config) {
// Local settings (e.g. for currently loaded STAC entity)
Expand Down Expand Up @@ -587,6 +588,20 @@ function getStore(config) {
}
},
actions: {
async switchLocale(cx, locale) {
if (!cx.state.supportedLocales.includes(locale)) {
console.error(`Language '${locale}' is not supported.`);
return;
}

// No messages in cache, load them
if (Utils.size(i18n.messages[locale]) <= 1) { // languages key is already set thus 1 and not 0
const messages = await import(`../locales/${locale}/texts.json`);
i18n.mergeLocaleMessage(locale, messages.default);
}

cx.commit('config', {locale});
},
async setAuth(cx, value) {
if (!Utils.hasText(value)) {
value = null;
Expand Down
2 changes: 1 addition & 1 deletion src/views/Catalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h2>Description</h2>
<DeprecationNotice v-if="data.deprecated" :data="data" />
<AnonymizedNotice v-if="data['anon:warning']" :warning="data['anon:warning']" />
<ReadMore v-if="data.description" :lines="10" text="Read more" text-less="Read less">
<ReadMore v-if="data.description" :lines="10" :text="$t('read.more')" :text-less="$t('read.less')">
<Description :description="data.description" />
</ReadMore>
<Keywords v-if="Array.isArray(data.keywords) && data.keywords.length > 0" :keywords="data.keywords" />
Expand Down
2 changes: 1 addition & 1 deletion src/views/Item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<h2 v-if="data.properties.description">Description</h2>
<DeprecationNotice v-if="data.properties.deprecated" :data="data" />
<AnonymizedNotice v-if="data.properties['anon:warning']" :warning="data.properties['anon:warning']" />
<ReadMore v-if="data.properties.description" :lines="10">
<ReadMore v-if="data.properties.description" :lines="10" :text="$t('read.more')" :text-less="$t('read.less')">
<Description :description="data.properties.description" />
</ReadMore>
<Keywords v-if="Array.isArray(data.properties.keywords) && data.properties.keywords.length > 0" :keywords="data.properties.keywords" />
Expand Down
16 changes: 8 additions & 8 deletions src/views/SelectDataSource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<b-col>
<b-form @submit="go">
<b-form-group
id="select" :label="$t('specifyCatalog')" label-for="url"
id="select" :label="$t('index.specifyCatalog')" label-for="url"
:invalid-feedback="error" :state="valid"
>
<b-form-input id="url" type="url" :value="url" @input="setUrl" placeholder="https://..." />
</b-form-group>
<b-button type="submit" variant="primary">{{ $t('load') }}</b-button>
<b-button type="submit" variant="primary">{{ $t('index.load') }}</b-button>
</b-form>
<hr>
<b-form-group v-if="stacIndex.length > 0" id="stacIndex" :label="$t('selectStacIndex')">
<b-form-group v-if="stacIndex.length > 0" id="stacIndex" :label="$t('index.selectStacIndex')">
<b-list-group class="stacIndex">
<template v-for="catalog in stacIndex">
<b-list-group-item
Expand All @@ -21,8 +21,8 @@
<div class="d-flex w-100 justify-content-between">
<strong class="mb-1">{{ catalog.title }}</strong>
<small>
<b-badge v-if="catalog.isApi" variant="dark" pill>API</b-badge>
<b-badge v-else variant="light" pill>Catalog</b-badge>
<b-badge v-if="catalog.isApi" variant="dark" pill>{{ $t('index.api') }}</b-badge>
<b-badge v-else variant="light" pill>{{ $t('index.catalog') }}</b-badge>
</small>
</div>
<p class="mb-1"><Description :description="catalog.summary" :compact="true" /></p>
Expand Down Expand Up @@ -69,14 +69,14 @@ export default {
try {
let url = new URL(this.url);
if (!url.protocol) {
return 'The URL is missing a protocol.';
return this.$t('index.urlMissingProtocol');
}
else if (!url.host) {
return 'The URL is missing a host.';
return this.$t('index.urlMissingHost');
}
return null;
} catch (error) {
return 'The URL is invalid.';
return this.$t('index.urlInvalid');
}
}
},
Expand Down

0 comments on commit 11d09ac

Please sign in to comment.