Update
This commit is contained in:
parent
3a1e4302ca
commit
d377613298
|
@ -12,8 +12,6 @@
|
||||||
<meta property="og:url" content="">
|
<meta property="og:url" content="">
|
||||||
<link rel="icon" type="image/png" href="/favicon.png"/>
|
<link rel="icon" type="image/png" href="/favicon.png"/>
|
||||||
|
|
||||||
<link rel="preload" href="/locales/available.json" as="fetch" type="application/json" crossorigin="anonymous">
|
|
||||||
|
|
||||||
<!--Load libraries-->
|
<!--Load libraries-->
|
||||||
|
|
||||||
<!--Load fonts-->
|
<!--Load fonts-->
|
||||||
|
|
|
@ -66,40 +66,38 @@ function onlyUnique(value, index, array) {
|
||||||
return array.indexOf(value) === index;
|
return array.indexOf(value) === index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let locales = {
|
||||||
|
en: "English",
|
||||||
|
ru: "Русский"
|
||||||
|
}
|
||||||
|
|
||||||
export function loadLocaleContent(content,componentName,loaded,callback) {
|
export function loadLocaleContent(content,componentName,loaded,callback) {
|
||||||
|
let locale
|
||||||
let langs
|
let langs
|
||||||
let localesAvailable
|
let localesAvailable = Object.keys(locales)
|
||||||
let locale = localStorage.getItem("locale")
|
let localeUrl = location.href.split("/").filter(x => localesAvailable.includes(x))
|
||||||
if (locale==null) {
|
if (localeUrl.length>0) {
|
||||||
langs = navigator.languages.map(x => x.split("-")[0]).filter(onlyUnique)
|
locale = localeUrl
|
||||||
}
|
}
|
||||||
getData("/locales/available.json",function(response) {
|
else {
|
||||||
if (locale!=null) {
|
langs = navigator.languages.map(x => x.split("-")[0]).filter(onlyUnique)
|
||||||
getData("/locales/" + locale + "/" + componentName + ".json" ,function(response) {
|
for (let lang of langs) {
|
||||||
let parsed = JSON.parse(response)
|
if (localesAvailable.includes(lang)) {
|
||||||
content.set(parsed)
|
locale = lang
|
||||||
if (callback!=undefined) {
|
|
||||||
callback(locale)
|
|
||||||
}
|
|
||||||
loaded = 1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
localesAvailable = JSON.parse(response)
|
|
||||||
for (let lang of langs) {
|
|
||||||
if (localesAvailable.includes(lang)) {
|
|
||||||
getData("/locales/" + lang + "/" + componentName + ".json" ,function(response) {
|
|
||||||
let parsed = JSON.parse(response)
|
|
||||||
content.set(parsed)
|
|
||||||
if (callback!=undefined) {
|
|
||||||
callback(locale)
|
|
||||||
}
|
|
||||||
loaded = 1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
if (locale==undefined) {
|
||||||
|
locale = "en"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getData("/locales/" + locale + "/" + componentName + ".json" ,function(response) {
|
||||||
|
let parsed = JSON.parse(response)
|
||||||
|
content.set(parsed)
|
||||||
|
if (callback!=undefined) {
|
||||||
|
callback(locale)
|
||||||
|
}
|
||||||
|
loaded = 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
["en","ru"]
|
|
|
@ -5,7 +5,7 @@
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import { communities, addMarkersCommunities } from '/js/communities.js'
|
import { communities, addMarkersCommunities } from '/js/communities.js'
|
||||||
import { loadLocaleContent,getLocale } from "/js/libraries/serverTools.js"
|
import { loadLocaleContent, getLocale } from "/js/libraries/serverTools.js"
|
||||||
|
|
||||||
// Import components
|
// Import components
|
||||||
import "/js/components/map-component.js"
|
import "/js/components/map-component.js"
|
||||||
|
|
|
@ -55,9 +55,9 @@
|
||||||
<div id="call-to-action-list">
|
<div id="call-to-action-list">
|
||||||
<p>{$content.findOur}</p>
|
<p>{$content.findOur}</p>
|
||||||
<ol>
|
<ol>
|
||||||
<li><a href="/groups">{$content.group}</a>,</li>
|
<li><a href={"/" + locale[0] + "/groups"}>{$content.group}</a>,</li>
|
||||||
<li><a href="/communities">{$content.community}</a> {$content.or}</li>
|
<li><a href={"/" + locale[0] + "/communities"}>{$content.community}</a> {$content.or}</li>
|
||||||
<li><a href="/cooperatives">{$content.cooperative}</a></li>
|
<li><a href={"/" + locale[0] + "/cooperatives"}>{$content.cooperative}</a></li>
|
||||||
</ol>
|
</ol>
|
||||||
<p>{$content.nearYou}</p>
|
<p>{$content.nearYou}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,17 +4,18 @@
|
||||||
|
|
||||||
// Import statements
|
// Import statements
|
||||||
import { onMount, getContext } from 'svelte'
|
import { onMount, getContext } from 'svelte'
|
||||||
import { loadLocaleContent } from "/js/libraries/serverTools.js"
|
import { writable } from 'svelte/store'
|
||||||
import { writable } from 'svelte/store';
|
import { loadLocaleContent, getLocale, locales } from "/js/libraries/serverTools.js"
|
||||||
|
|
||||||
// Main code
|
// Main code
|
||||||
let hambInput
|
let hambInput
|
||||||
let navbar
|
let navbar
|
||||||
let localesDropdown
|
let localesDropdown
|
||||||
let loaded
|
let loaded
|
||||||
|
let locale = []
|
||||||
let content = writable({})
|
let content = writable({})
|
||||||
|
|
||||||
loadLocaleContent(content,"navbar-component",loaded)
|
loadLocaleContent(content,"navbar-component",loaded,(lang) => getLocale(locale,lang))
|
||||||
|
|
||||||
function changeNavbar() {
|
function changeNavbar() {
|
||||||
if (hambInput.checked) {
|
if (hambInput.checked) {
|
||||||
|
@ -43,7 +44,11 @@
|
||||||
|
|
||||||
function changeLocale(lang) {
|
function changeLocale(lang) {
|
||||||
localStorage.setItem("locale",lang)
|
localStorage.setItem("locale",lang)
|
||||||
location.reload()
|
let locSplit = location.href.split("/")
|
||||||
|
let localesSymbols = Object.keys(locales)
|
||||||
|
locSplit = locSplit.filter(x => !localesSymbols.includes(x))
|
||||||
|
let loc = locSplit.slice(0,locSplit.length-1).join("/") + "/" + lang + "/" + locSplit[locSplit.length-1]
|
||||||
|
location.href = loc
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
@ -60,19 +65,19 @@
|
||||||
<input bind:this={hambInput} type="checkbox" id="side-menu" on:click={changeNavbar}>
|
<input bind:this={hambInput} type="checkbox" id="side-menu" on:click={changeNavbar}>
|
||||||
<label id="hamb" for="side-menu"><span id="hamb-line"></span></label>
|
<label id="hamb" for="side-menu"><span id="hamb-line"></span></label>
|
||||||
<!-- Logo -->
|
<!-- Logo -->
|
||||||
<a id=logo-container href="/">
|
<a id=logo-container href={"/" + locale[0] + "/"}>
|
||||||
<img src="img/common/flag.png" id="navbar-logo" alt="logo">
|
<img src="/img/common/flag.png" id="navbar-logo" alt="logo">
|
||||||
<span id="navbar-logo-text">{$content.orgName}</span>
|
<span id="navbar-logo-text">{$content.orgName}</span>
|
||||||
</a>
|
</a>
|
||||||
<!-- Menu -->
|
<!-- Menu -->
|
||||||
<nav id="nav">
|
<nav id="nav">
|
||||||
<ul id="menu">
|
<ul id="menu">
|
||||||
<li><a href="/manifesto">{$content.manifesto}</a></li>
|
<li><a href={"/"+locale+"/manifesto"}>{$content.manifesto}</a></li>
|
||||||
<li><a href="/join-us">{$content.joinUs}</a></li>
|
<li><a href={"/"+locale+"/join-us"}>{$content.joinUs}</a></li>
|
||||||
<li><a href="/groups">{$content.groups}</a></li>
|
<li><a href={"/"+locale+"/groups"}>{$content.groups}</a></li>
|
||||||
<li><a href="/communities">{$content.communities}</a></li>
|
<li><a href={"/"+locale+"/communities"}>{$content.communities}</a></li>
|
||||||
<li><a href="/cooperatives">{$content.cooperatives}</a></li>
|
<li><a href={"/"+locale+"/cooperatives"}>{$content.cooperatives}</a></li>
|
||||||
<li><a href="/partners">{$content.partners}</a></li>
|
<li><a href={"/"+locale+"/partners"}>{$content.partners}</a></li>
|
||||||
<li id="locales">
|
<li id="locales">
|
||||||
<button on:click={showLocales}>
|
<button on:click={showLocales}>
|
||||||
<picture>
|
<picture>
|
||||||
|
@ -83,8 +88,9 @@
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<div bind:this={localesDropdown} id="locales-dropdown">
|
<div bind:this={localesDropdown} id="locales-dropdown">
|
||||||
<button on:click={() => changeLocale("en")}>English</button>
|
{#each Object.entries(locales) as [loc,name]}
|
||||||
<button on:click={() => changeLocale("ru")}>Русский</button>
|
<button on:click={() => changeLocale(loc)}>{name}</button>
|
||||||
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -66,40 +66,38 @@ function onlyUnique(value, index, array) {
|
||||||
return array.indexOf(value) === index;
|
return array.indexOf(value) === index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let locales = {
|
||||||
|
en: "English",
|
||||||
|
ru: "Русский"
|
||||||
|
}
|
||||||
|
|
||||||
export function loadLocaleContent(content,componentName,loaded,callback) {
|
export function loadLocaleContent(content,componentName,loaded,callback) {
|
||||||
|
let locale
|
||||||
let langs
|
let langs
|
||||||
let localesAvailable
|
let localesAvailable = Object.keys(locales)
|
||||||
let locale = localStorage.getItem("locale")
|
let localeUrl = location.href.split("/").filter(x => localesAvailable.includes(x))
|
||||||
if (locale==null) {
|
if (localeUrl.length>0) {
|
||||||
langs = navigator.languages.map(x => x.split("-")[0]).filter(onlyUnique)
|
locale = localeUrl
|
||||||
}
|
}
|
||||||
getData("/locales/available.json",function(response) {
|
else {
|
||||||
if (locale!=null) {
|
langs = navigator.languages.map(x => x.split("-")[0]).filter(onlyUnique)
|
||||||
getData("/locales/" + locale + "/" + componentName + ".json" ,function(response) {
|
for (let lang of langs) {
|
||||||
let parsed = JSON.parse(response)
|
if (localesAvailable.includes(lang)) {
|
||||||
content.set(parsed)
|
locale = lang
|
||||||
if (callback!=undefined) {
|
|
||||||
callback(locale)
|
|
||||||
}
|
|
||||||
loaded = 1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
localesAvailable = JSON.parse(response)
|
|
||||||
for (let lang of langs) {
|
|
||||||
if (localesAvailable.includes(lang)) {
|
|
||||||
getData("/locales/" + lang + "/" + componentName + ".json" ,function(response) {
|
|
||||||
let parsed = JSON.parse(response)
|
|
||||||
content.set(parsed)
|
|
||||||
if (callback!=undefined) {
|
|
||||||
callback(locale)
|
|
||||||
}
|
|
||||||
loaded = 1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
if (locale==undefined) {
|
||||||
|
locale = "en"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getData("/locales/" + locale + "/" + componentName + ".json" ,function(response) {
|
||||||
|
let parsed = JSON.parse(response)
|
||||||
|
content.set(parsed)
|
||||||
|
if (callback!=undefined) {
|
||||||
|
callback(locale)
|
||||||
|
}
|
||||||
|
loaded = 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,4 @@ https://www.libsoc.org/join-us
|
||||||
https://www.libsoc.org/groups
|
https://www.libsoc.org/groups
|
||||||
https://www.libsoc.org/communities
|
https://www.libsoc.org/communities
|
||||||
https://www.libsoc.org/cooperatives
|
https://www.libsoc.org/cooperatives
|
||||||
https://www.libsoc.org/affiliates
|
https://www.libsoc.org/partners
|
|
@ -5,17 +5,23 @@ using Server.BasicController
|
||||||
|
|
||||||
#---Basic-----------------------------------------------------------
|
#---Basic-----------------------------------------------------------
|
||||||
|
|
||||||
route("/", BasicController.landing, named = :landing)
|
route("/:locale/manifesto", BasicController.manifesto, named = :manifest)
|
||||||
|
route("/manifesto", BasicController.manifesto)
|
||||||
|
|
||||||
route("/manifesto", BasicController.manifesto, named = :manifest)
|
route("/:locale/join-us", BasicController.join_us, named = :join_us)
|
||||||
|
route("/join-us", BasicController.join_us)
|
||||||
|
|
||||||
route("/join-us", BasicController.join_us, named = :join_us)
|
route("/:locale/groups", BasicController.groups, named = :groups)
|
||||||
|
route("/groups", BasicController.groups)
|
||||||
|
|
||||||
route("/groups", BasicController.groups, named = :groups)
|
route("/:locale/cooperatives", BasicController.cooperatives, named = :cooperatives)
|
||||||
|
route("/cooperatives", BasicController.cooperatives)
|
||||||
|
|
||||||
route("/cooperatives", BasicController.cooperatives, named = :cooperatives)
|
route("/:locale/communities", BasicController.communities, named = :communities)
|
||||||
|
route("/communities", BasicController.communities)
|
||||||
|
|
||||||
route("/communities", BasicController.communities, named = :communities)
|
route("/:locale/partners", BasicController.partners, named = :partners)
|
||||||
|
route("/partners", BasicController.partners)
|
||||||
route("/partners", BasicController.partners, named = :partners)
|
|
||||||
|
|
||||||
|
route("/:locale", BasicController.landing, named = :landing)
|
||||||
|
route("/", BasicController.landing)
|
||||||
|
|
Loading…
Reference in New Issue