Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Edit on Github" and "Translate to..." buttons #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,202 +21,252 @@ paths = "safe"

[extra]
stripe = "https://donate.organicmaps.app/"
github_source = "https://github.com/organicmaps/organicmaps.github.io"

# Default English translation
[translations]
address = "Address"
back = "Back to News"
contact = "Contact Us"
edit_on_github = "Edit on GitHub"
install-appgallery = "Install Organic Maps from Huawei AppGallery"
install-appstore = "Install Organic Maps from the AppStore"
install-googleplay = "Install Organic Maps from Google Play"
install-fdroid="Install Organic Maps from F-Droid"
language = "English"
name = "Name"
token = "Token"
translate_to = "Translate to…"

# Please sort all other translation sections and values in alphabetical order.
[languages.de]
[languages.de.translations]
address = "Adresse"
back = "Zurück zu den Neuigkeiten"
contact = "Kontakt"
edit_on_github = "Auf GitHub bearbeiten"
install-appgallery = "Installiere Organic Maps aus der Huawei AppGallery"
install-appstore = "Installiere Organic Maps aus dem AppStore"
install-googleplay = "Installiere Organic Maps von Google Play"
install-fdroid = "Installiere Organic Maps aus F-Droid"
language = "Deutsch"
name = "Name"
token = "Token"
translate_to = "Übersetzen in…"

[languages.fr]
[languages.fr.translations]
address = "Adresse"
back = "Retour aux actualités"
contact = "Contact"
edit_on_github = "Modifier sur GitHub"
install-appgallery = "Installez Organic Maps depuis l'AppGallery"
install-appstore = "Installez Organic Maps depuis l'AppStore"
install-googleplay = "Installez Organic Maps depuis Google Play"
install-fdroid = "Installez Organic Maps depuis F-Droid"
language = "Français"
name = "Nom"
token = "Jeton"
translate_to = "Traduire en…"

[languages.it]
[languages.it.translations]
address = "Indirizzo"
back = "Indietro"
contact = "Contattaci"
edit_on_github = "Modifica su GitHub"
install-appgallery = "Installa Organic Maps da Huawei AppGallery"
install-appstore = "Installa Organic Maps dall'AppStore"
install-googleplay = "Installa Organic Maps da Google Play"
install-fdroid = "Installa Organic Maps da F-Droid"
language = "Italiano"
name = "Nome"
token = "Token"
translate_to = "Tradurre in…"

[languages.pl]
[languages.pl.translations]
address = "Adres"
back = "Powrót do Nowości"
contact = "Kontakt z nami"
edit_on_github = "Edytuj na GitHubie"
install-appgallery = "Zainstaluj Organic Maps z Huawei AppGallery"
install-appstore = "Zainstaluj Organic Maps z AppStore"
install-googleplay = "Zainstaluj Organic Maps z Google Play"
install-fdroid = "Zainstaluj Organic Maps z F-Droid"
language = "Polski"
name = "Nazwa"
token = "Token"
translate_to = "Przetłumacz na…"

[languages.ru]
[languages.ru.translations]
address = "Адрес"
back = "Назад к новостям"
contact = "Связаться с нами"
edit_on_github = "Редактировать на GitHub"
install-appgallery = "Установите Organic Maps из Huawei AppGallery"
install-appstore = "Установите Organic Maps из AppStore"
install-googleplay = "Установите Organic Maps из Google Play"
install-fdroid = "Установите Organic Maps из F-Droid"
language = "Русский"
name = "Название"
token = "Токен"
translate_to = "Перевести на…"

[languages.tr]
[languages.tr.translations]
address = "Adres"
back = "Haberlere geri dön"
contact = "Bize ulaşın"
edit_on_github = "GitHub'da Düzenle"
install-appgallery = "Organic Maps'i Huawei AppGallery'den İndir"
install-appstore = "Organic Maps'i AppStore'dan İndir"
install-googleplay = "Organic Maps'i Google Play'den İndir"
install-fdroid = "Organic Maps'i F-Droid'den İndir"
language = "Türkçe"
name = "İsim"
token = "Token"
translate_to = "Tercüme et…"

[languages.id]
[languages.id.translations]
address = "Alamat"
back = "Kembali ke Berita"
contact = "Hubungi Kami"
edit_on_github = "Edit di GitHub"
install-appgallery = "Instal Organic Maps dari Huawei AppGallery"
install-appstore = "Instal Organic Maps dari AppStore"
install-googleplay = "Instal Organic Maps dari Google Play"
install-fdroid = "Instal Peta Organik dari F-Droid"
language = "Bahasa Indonesia"
name = "Nama"
token = "Token"
translate_to = "Terjemahkan ke…"

[languages.cs]
[languages.cs.translations]
address = "Adresa"
back = "Zpět na novinky"
contact = "Kontaktujte nás"
edit_on_github = "Upravit na GitHubu"
install-appgallery = "Instalace aplikace Organic Maps z galerie aplikací Huawei"
install-appstore = "Instalace aplikace Organic Maps z AppStore"
install-googleplay = "Instalace Organic Maps z Google Play"
install-fdroid = "Instalace Organic Maps z F-Droid"
language = "čeština"
name = "Název"
token = "Token"
translate_to = "Přeložit do…"

[languages.pt-BR.translations]
address = "Endereço"
back = "Voltar às Notícias"
contact = "Contate-nos"
edit_on_github = "Editar no GitHub"
install-appgallery = "Instale Organic Maps a partir da Huawei AppGallery"
install-appstore = "Instale Organic Maps a partir da AppStore"
install-googleplay = "Instale Organic Maps a partir da Google Play"
install-fdroid = "Instale Organic Maps a partir do F-Droid"
language = "Português (Brazil)"
name = "Nome"
token = "Token"
translate_to = "Traduzir para…"

[languages.es.translations]
address = "Dirección"
back = "Volver a Noticias"
contact = "Contacte con nosotros"
edit_on_github = "Editar en GitHub"
install-appgallery = "Instalar Organic Maps desde la AppGallery de Huawei"
install-appstore = "Instalar Organic Maps desde el AppStore"
install-googleplay = "Instalar Organic Maps desde Google Play"
install-fdroid = "Instalar Organic Maps desde F-Droid"
language = "Español"
name = "Nombre"
token = "Ficha"
translate_to = "Traducir a…"

[languages.nl.translations]
address = "Adres"
back = "Terug naar Nieuws"
contact = "Contacteer ons"
edit_on_github = "Bewerken op GitHub"
install-appgallery = "Installeer Organic Maps in de Huawei AppGallery"
install-appstore = "Installeer Organic Maps in de AppStore"
install-googleplay = "Installeer Organic Maps op Google Play"
install-fdroid = "Installeer Organic Maps op F-Droid"
language = "Dutch"
name = "Naam"
token = "Token"
translate_to = "Vertalen naar…"

[languages.eu.translations]
address = "Helbidea"
back = "Back to News"
contact = "Harremanetan jarri"
edit_on_github = "Editatu GitHub-en"
install-appgallery = "Install Organic Maps from Huawei AppGallery"
install-appstore = "Install Organic Maps from the AppStore"
install-googleplay = "Install Organic Maps from Google Play"
install-fdroid = "Install Organic Maps from F-Droid"
language = "Euskara"
name = "Izena"
token = "token"
translate_to = "Itzuli…"

[languages.hu.translations]
address = "Cím"
back = "Vissza a Hírekhez"
contact = "Kapcsolat"
edit_on_github = "Szerkesztés a GitHubon"
install-appgallery = "Telepítse az Organic Maps-et a Huawei AppGalériából"
install-appstore = "Telepítse az Organic Maps-et az AppStore-ból"
install-googleplay = "Telepítse az Organic Maps-et a Google Play-ről"
install-fdroid = "Telepítse az Organic Maps-et az F-Droidról"
language = "Magyar"
name = "Név"
token = "Token"
translate_to = "Fordítás…"

[languages.hi.translations]
address = "पता"
back = "ख़बरों पर वापस जाएं"
contact = "संपर्क करें"
edit_on_github = "गिटहब पर संपादित करें"
install-appgallery = "Huawei AppGallery से ऑर्गेनिक मैप इंस्टॉल करें"
install-appstore = "AppStore से ऑर्गेनिक मैप इंस्टॉल करें"
install-googleplay = "गूगल प्ले से ऑर्गेनिक मैप इंस्टॉल करें"
install-fdroid = "F-Droid से ऑर्गेनिक मैप्स इंस्टॉल करें"
language = "अंग्रेजी"
name = "नाम"
token = "टोकन/Token"
translate_to = "अनुवाद करने के लिए…"

[languages.uk.translations]
address = "Адреса"
back = "Назад до Новин"
contact = "Контакти"
edit_on_github = "Редагувати на GitHub"
install-appgallery = "Встановіть Organic Maps з Huawei AppGallery"
install-appstore = "Встановіть Organic Maps з AppStore"
install-googleplay = "Встановіть Organic Maps з Google Play"
install-fdroid = "Встановіть Organic Maps з F-Droid"
language = "Українська"
name = "Назва"
token = "Токен"
translate_to = "Перекласти на…"

[languages.ca.translations]
address = "Adreça"
back = "Torna a Notícies"
contact = "Contacte"
edit_on_github = "Edita a GitHub"
install-appgallery = "Instal·leu l’Organic Maps des de l’AppGallery de Huawei"
install-appstore = "Instal·leu l’Organic Maps des de l’AppStore"
install-googleplay = "Instal·leu l’Organic Maps des del Google Play"
install-fdroid = "Instal·leu l’Organic Maps des del F-Droid"
language = "Català"
name = "Nom"
token = "Testimoni"
translate_to = "Traduir a…"
2 changes: 1 addition & 1 deletion content/_index.hu.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Az **Organic Maps** egy ingyenes Android és iOS offline térképalkalmazás uta

**Az Organic Maps** egyike azon kevés alkalmazásoknak, amelyek manapság 100%-ban támogatják a funkciókat aktív internetkapcsolat nélkül. Telepítse az Organic Maps-et, töltse le a térképeket, dobja el a SIM-kártyáját (máskülönben a szolgáltatója folyamatosan nyomon követi Önt), és egyetlen akkumulátortöltéssel, a hálózatra küldött egyetlen byte nélkül induljon el egy egyhetes útra.

### Töltse le és telepítse az Organic Maps-et az [AppStore][appstore], [Google Play][googleplay], [FDroid][fdroid], [Huawei AppGallery][appgallery] {#install} alkalmazásboltokból
### Töltse le és telepítse az Organic Maps-et az [AppStore][appstore], [Google Play][googleplay], [FDroid][fdroid], [Huawei AppGallery][appgallery] {#install}

{{ badges(lang='hu') }}

Expand Down
2 changes: 1 addition & 1 deletion po/content.hu.po
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ msgstr "**Az Organic Maps** egyike azon kevés alkalmazásoknak, amelyek manaps
#: content/_index.md
#, no-wrap
msgid "Download and install Organic Maps from [AppStore][appstore], [Google Play][googleplay], [FDroid][fdroid], [Huawei AppGallery][appgallery] {#install}"
msgstr "Töltse le és telepítse az Organic Maps-et az [AppStore][appstore], [Google Play][googleplay], [FDroid][fdroid], [Huawei AppGallery][appgallery] {#install} alkalmazásboltokból"
msgstr "Töltse le és telepítse az Organic Maps-et az [AppStore][appstore], [Google Play][googleplay], [FDroid][fdroid], [Huawei AppGallery][appgallery] {#install}"

#. type: Plain text
#: content/_index.md
Expand Down
5 changes: 5 additions & 0 deletions sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,8 @@ footer {
.back_to_news {
margin-top: 1rem;
}

.translate-menu {
padding-bottom: 1rem;
text-align: right;
}
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
</main>

<footer>
{% include 'translate_menu.html' %}
{% include 'bottom_menu.html' %}
<p>
<span>© 2022 <a href="mailto:[email protected]">Organic Maps OÜ</a>, reg. code 16225385</span>
Expand Down
92 changes: 92 additions & 0 deletions templates/translate_menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<script>
// Implement format if it's not implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
}

function onTranslateToSelected(el) {
// No language element.
if (!el.value) return;

console.log(el.value);

el.disabled = true;
document.body.style.cursor = 'wait';

var dir = el.getAttribute('data-dir');
var basename = encodeURIComponent(el.getAttribute('data-basename'));
var fromLanguage = document.documentElement.getAttribute('lang');
var toLanguage = el.value;

var sourceUrl = '{{ config.extra.github_source | safe }}/'.replace(
'https://github.com', 'https://raw.githubusercontent.com');
// Non-ASCII texts are longer and do not fit easily into Github limits, see below.
// if (fromLanguage !== 'en') {
// sourceUrl = '{0}master/content/{1}{2}.{3}.md'.format(sourceUrl, dir, basename, fromLanguage);
// } else {
sourceUrl = '{0}master/content/{1}{2}.md'.format(sourceUrl, dir, basename);
//}

var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
var markdownContent = encodeURIComponent(request.responseText);

// Generate URL to create a new page translation.
var filename = encodeURIComponent('{0}.{1}.md'.format(basename, toLanguage));
var lastDir = dir.split('/');
// Last path element can be empty due to a trailing slash.
lastDir = lastDir.pop() || lastDir.pop();
// Github has strange paths/params processing, fix a special case for root _index.md translations.
if (lastDir.length == 0) lastDir = 'content';
var newFileUrl = '{{ config.extra.github_source | safe }}/new/master/content/{0}?filename={1}/{2}&value={3}'
.format(dir.substr(0, dir.length - 1), lastDir, filename, markdownContent);

// Github limits max URL len to 8192 and shows error for too long urls.
if (newFileUrl.length > 8192) {
var cutTextStub = '\n\nPlease insert here the remaining text from ' + sourceUrl;
newFileUrl = newFileUrl.substring(0, 8191 - cutTextStub.length) + cutTextStub;
}
window.open(newFileUrl, '_blank');
} else {
// TODO: Display visible errors.
console.log('Error getting ' + sourceUrl);
}
// Restore cursor and element.
el.disabled = false;
el.selectedIndex = 0;
document.body.style.cursor = 'default';
}
};
request.open('GET', sourceUrl, true);
request.send(null);

console.log(sourceUrl);
}

// TODO: Show Translate to... option only for supported user's navigator languages
// var pageTranslations = {# resource.translations | map(attribute="lang") | json_encode() | safe #};
// var userPreferredLanguages = navigator.languages ? navigator.languages : [navigator.language];

</script>
<nav class="translate-menu">
<a href="{{ config.extra.github_source ~ '/edit/master/content/' ~ resource.relative_path | safe }}">{{ trans(key='edit_on_github', lang=lang) }}</a>
{% set pathArray = resource.relative_path | split(pat='/') %}
{% set contentDir = pathArray | slice(end=-1) | join(sep='/') %}
{% set baseFileName = pathArray | last | split(pat='.') | first %}
<select class="translate-to" onchange="onTranslateToSelected(this)" data-dir="{{ contentDir ~ '/' }}" data-basename="{{ baseFileName }}">
<option value="">{{ trans(key='translate_to', lang=lang) }}</option>
<!-- TODO: Dynamically generate the list of needed languages and their names using Intl api or hard-coded list:
See https://stackoverflow.com/a/69968496 -->
<option value="es">Español</option>
<option value="fr">Français</option>
<option value="pt">Português</option>
<option value="be">Беларуская</option>
</select>
</nav>