Multi Language part 1
This commit is contained in:
1 parent
950ffd6c10
commit
55a63d9c88
7 files changed
+140
-17
No files matched your search
@@ -202,6 +202,11 @@
|
||||
"name": "Strings",
|
||||
"propertyName": "strings",
|
||||
"functionName": "newSuperalgosUtilitiesStrings"
|
||||
},
|
||||
{
|
||||
"name": "Languages",
|
||||
"propertyName": "languages",
|
||||
"functionName": "newSuperalgosUtilitiesLanguages"
|
||||
}
|
||||
],
|
||||
"spaces": [
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
"style": "Text",
|
||||
"text": "Vaina 1"
|
||||
},
|
||||
{
|
||||
"style": "Youtube",
|
||||
"text": "fO-CHEEVneI"
|
||||
},
|
||||
{
|
||||
"style": "Link",
|
||||
"text": "Google->google.com"
|
||||
@@ -24,7 +20,7 @@
|
||||
},
|
||||
{
|
||||
"style": "Hierarchy",
|
||||
"text": "Superalgos->Task->5"
|
||||
"text": "Superalgos->Task->2"
|
||||
},
|
||||
{
|
||||
"style": "Note",
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"topic": "Docs Languages",
|
||||
"pageNumber": "1",
|
||||
"type": "Docs In English",
|
||||
"definition": "The Docs articles are fully written in English. The system allow users to search / browse articles in other languages as well, as long as other users contribute translations.",
|
||||
"paragraphs": [
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Superalgos and any other integrated project are written in English, since English is considered the default language. Node types, variable names, etc., all is originally in English language. "
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "The Docs content can be translated by anyone willing to contribute some time doing so. That helps users to read the contents of the Docs in their native language. "
|
||||
},
|
||||
{
|
||||
"style": "Success",
|
||||
"text": "Users can switch between languages using the links provided at the footer of every page at the Docs."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"topic": "Docs Languages",
|
||||
"pageNumber": "2",
|
||||
"type": "Docs In Spanish",
|
||||
"definition": "Si bien la documentación esta originalmente escrita en Inglés, el sistema permite a cualquier usuario buscar contenido en su idioma nativo, siempre y cuando otros usuarios hayan contribuído traducciones de los artículos existentes escritos en el idioma por defecto que es el idioma Inglés. ",
|
||||
"paragraphs": [
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Es importante notar que por mas que uno seleccione un idioma, el contenido se mostrará en ingles en cada sitio donde todavía no ha sido traducido. El sistema permite a cualquier usuario contribuir traducciones con una granularidad a nivel de párrafos. Esto significa que si una página cualquiera pudiera tener todos, algunos o nigún párrafo traducido. Esto solo depende de cuales hayan sido traducidos previamente por miembros de la comunidad."
|
||||
},
|
||||
{
|
||||
"style": "Success",
|
||||
"text": "Para cambiar de un idioma a otro se debe usar los links en el pie de cada página."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"topic": "Docs Languages",
|
||||
"pageNumber": "3",
|
||||
"type": "Docs In Russian",
|
||||
"definition": "Write here a summary for this topic page.",
|
||||
"paragraphs": [
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
function newSuperalgosDocSpace() {
|
||||
const MODULE_NAME = 'Doc Space'
|
||||
let thisObject = {
|
||||
changeLanguage: changeLanguage,
|
||||
isVisible: undefined,
|
||||
sidePanelTab: undefined,
|
||||
container: undefined,
|
||||
@@ -16,6 +17,7 @@ function newSuperalgosDocSpace() {
|
||||
}
|
||||
|
||||
let isInitialized = false
|
||||
const DEFAULT_LANGUAGE = 'EN'
|
||||
const DOCS_SPACE_WIDTH = 900
|
||||
const newParagraphText = "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode."
|
||||
|
||||
@@ -44,6 +46,7 @@ function newSuperalgosDocSpace() {
|
||||
let menuLabelsMap = new Map()
|
||||
let command
|
||||
let docsIndex = []
|
||||
let language
|
||||
|
||||
return thisObject
|
||||
|
||||
@@ -59,6 +62,16 @@ function newSuperalgosDocSpace() {
|
||||
setUpContextMenu()
|
||||
setUpMenuItemsMap()
|
||||
|
||||
/*
|
||||
Getting the used preferred languague
|
||||
*/
|
||||
if (window.localStorage.getItem('Docs Language') !== null && window.localStorage.getItem('Docs Language') !== undefined && window.localStorage.getItem('Docs Language') !== 'undefined') {
|
||||
language = window.localStorage.getItem('Docs Language')
|
||||
} else {
|
||||
window.localStorage.setItem('Docs Language', DEFAULT_LANGUAGE)
|
||||
language = DEFAULT_LANGUAGE
|
||||
}
|
||||
|
||||
isInitialized = true
|
||||
|
||||
function setUpContextMenu() {
|
||||
@@ -368,6 +381,13 @@ function newSuperalgosDocSpace() {
|
||||
intialize()
|
||||
}
|
||||
|
||||
function changeLanguage(pLanguage) {
|
||||
window.localStorage.setItem('Docs Language', language)
|
||||
language = pLanguage
|
||||
let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(language)
|
||||
navigateTo('Superalgos', 'Topic', 'Docs In ' + languageLabel)
|
||||
}
|
||||
|
||||
function cleanTextForSearch(text) {
|
||||
let result = replaceSpecialCharactersForSpaces(text)
|
||||
result = result.replaceAll(' ', '')
|
||||
@@ -2824,7 +2844,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = ''
|
||||
role = ''
|
||||
key = key + '-text'
|
||||
innerHTML = addBold(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addBold(innerHTML)
|
||||
innerHTML = addCodeToCamelCase(innerHTML)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
@@ -2835,7 +2856,7 @@ function newSuperalgosDocSpace() {
|
||||
prefix = ''
|
||||
role = ''
|
||||
key = key + '-title'
|
||||
innerHTML = paragraph.text
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
break
|
||||
}
|
||||
case 'Subtitle': {
|
||||
@@ -2843,7 +2864,7 @@ function newSuperalgosDocSpace() {
|
||||
prefix = ''
|
||||
role = ''
|
||||
key = key + '-subtitle'
|
||||
innerHTML = paragraph.text
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
break
|
||||
}
|
||||
case 'Note': {
|
||||
@@ -2851,7 +2872,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = '<i class="docs-fa docs-note-circle"></i> <b>Note:</b>'
|
||||
role = 'role="alert"'
|
||||
key = key + '-note'
|
||||
innerHTML = addItalics(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
}
|
||||
@@ -2860,7 +2882,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = '<i class="docs-fa docs-check-square-o"></i> <b>Tip:</b>'
|
||||
role = 'role="alert"'
|
||||
key = key + '-success'
|
||||
innerHTML = addItalics(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
}
|
||||
@@ -2869,7 +2892,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = '<i class="docs-fa docs-warning-sign"></i> <b>Important:</b>'
|
||||
role = 'role="alert"'
|
||||
key = key + '-important'
|
||||
innerHTML = addItalics(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
}
|
||||
@@ -2878,7 +2902,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = '<i class="docs-fa docs-warning-sign"></i> <b>Warning:</b>'
|
||||
role = 'role="alert"'
|
||||
key = key + '-warning'
|
||||
innerHTML = addItalics(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
}
|
||||
@@ -2887,7 +2912,7 @@ function newSuperalgosDocSpace() {
|
||||
prefix = '<i class="docs-fa docs-warning-sign"></i> <b>Error:</b>'
|
||||
role = 'role="alert"'
|
||||
key = key + '-error'
|
||||
innerHTML = paragraph.text
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
break
|
||||
}
|
||||
case 'Callout': {
|
||||
@@ -2895,7 +2920,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = ''
|
||||
role = ''
|
||||
key = key + '-callout'
|
||||
innerHTML = addItalics(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
}
|
||||
@@ -2904,7 +2930,8 @@ function newSuperalgosDocSpace() {
|
||||
prefix = '<b>Summary:</b>'
|
||||
role = ''
|
||||
key = key + '-summary'
|
||||
innerHTML = addItalics(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
}
|
||||
@@ -2914,7 +2941,8 @@ function newSuperalgosDocSpace() {
|
||||
sufix = '</li>'
|
||||
role = ''
|
||||
key = key + '-list'
|
||||
innerHTML = addBold(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = addBold(innerHTML)
|
||||
innerHTML = addCodeToCamelCase(innerHTML)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
@@ -2926,7 +2954,8 @@ function newSuperalgosDocSpace() {
|
||||
sufix = '</table>'
|
||||
role = ''
|
||||
key = key + '-table'
|
||||
innerHTML = parseTable(paragraph.text)
|
||||
innerHTML = getTextBasedOnLanguage(paragraph)
|
||||
innerHTML = parseTable(innerHTML)
|
||||
innerHTML = addItalics(innerHTML)
|
||||
innerHTML = addToolTips(innerHTML)
|
||||
break
|
||||
@@ -3024,6 +3053,15 @@ function newSuperalgosDocSpace() {
|
||||
HTML = HTML + '<p><div id="' + key + '" ' + styleClass + ' ' + role + '>' + prefix + ' ' + innerHTML + sufix + '</div></p>'
|
||||
paragraphMap.set(key, paragraph)
|
||||
|
||||
function getTextBasedOnLanguage(paragraph) {
|
||||
if (paragraph.translations === undefined) { return paragraph.text }
|
||||
if (paragraph.translations.length === 0) { return paragraph.text }
|
||||
for (let i = 0; i < paragraph.translations.length; i++) {
|
||||
let translation = paragraph.translations[i]
|
||||
if (translation.language === language) { return translation.text }
|
||||
}
|
||||
return paragraph.text
|
||||
}
|
||||
}
|
||||
|
||||
function hightlightEmbeddedCode() {
|
||||
@@ -3239,6 +3277,8 @@ function newSuperalgosDocSpace() {
|
||||
}
|
||||
|
||||
function addFooter() {
|
||||
let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(language)
|
||||
|
||||
let HTML = ''
|
||||
|
||||
HTML = HTML + '<div class="docs-node-html-footer-container">' // Container Starts
|
||||
@@ -3249,6 +3289,14 @@ function newSuperalgosDocSpace() {
|
||||
|
||||
HTML = HTML + '<div onClick="UI.projects.superalgos.spaces.docsSpace.scrollToElement(\'docs-space-div\')" class="docs-plain-link"><kbd class=docs-kbd>BACK TO TOP ↑</kbd></div>'
|
||||
|
||||
HTML = HTML + '<p> </p>'
|
||||
HTML = HTML + 'You are currently reading the Docs in ' + languageLabel + '. To read the Docs in your language, follow one of these links:'
|
||||
HTML = HTML + '<ul>'
|
||||
HTML = HTML + '<li><a onClick="UI.projects.superalgos.spaces.docsSpace.changeLanguage(\'EN\')" class="docs-footer-link">English</a> — The collection of articles is complete in this language.</li>'
|
||||
HTML = HTML + '<li><a onClick="UI.projects.superalgos.spaces.docsSpace.changeLanguage(\'ES\')" class="docs-footer-link">Spanish</a> — Work in progress. You are invited to contribute translating content.</li>'
|
||||
HTML = HTML + '<li><a onClick="UI.projects.superalgos.spaces.docsSpace.changeLanguage(\'RU\')" class="docs-footer-link">Russian</a> — Work in progress. You are invited to contribute translating content.</li>'
|
||||
HTML = HTML + '</ul>'
|
||||
HTML = HTML + 'Other resources:'
|
||||
HTML = HTML + '<ul>'
|
||||
HTML = HTML + '<li><a href="https://superalgos.org/" target="_blank" class="docs-footer-link">Superalgos Project</a> — Learn more about the project.</li>'
|
||||
HTML = HTML + '<li><a href="https://t.me/superalgoscommunity" rel="nofollow" target="_blank" class="docs-footer-link">Community Group</a> — Lets talk Superalgos!</li>'
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
function newSuperalgosUtilitiesLanguages() {
|
||||
thisObject = {
|
||||
getLaguageLabel: getLaguageLabel
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function getLaguageLabel(language) {
|
||||
let languageLabel
|
||||
switch (language) {
|
||||
case 'EN': {
|
||||
languageLabel = 'English'
|
||||
break
|
||||
}
|
||||
case 'ES': {
|
||||
languageLabel = 'Spanish'
|
||||
break
|
||||
}
|
||||
case 'RU': {
|
||||
languageLabel = 'Russian'
|
||||
break
|
||||
}
|
||||
}
|
||||
return languageLabel
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user