This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add translations. (read README.md in /translations)
- Loading branch information
Showing
44 changed files
with
2,585 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[python: **/server/.py] | ||
[jinja2: **/client/html/**.html] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.settings-container { | ||
margin: 24px 0px 8px 0px; | ||
justify-content: center; | ||
} | ||
|
||
.settings-container span { | ||
font-size: 0.875rem; | ||
margin: 0; | ||
} | ||
|
||
.settings-container label { | ||
width: 24px; | ||
height: 16px; | ||
} | ||
|
||
.settings-container .field { | ||
justify-content: space-between; | ||
} | ||
|
||
.settings-container .checkbox input + label, | ||
.settings-container .checkbox input:checked + label:after { | ||
background: var(--colour-1); | ||
} | ||
|
||
.settings-container .checkbox input + label:after, | ||
.settings-container .checkbox input:checked + label { | ||
background: var(--colour-3); | ||
} | ||
|
||
.settings-container .checkbox label:after { | ||
left: 2px; | ||
width: 10px; | ||
height: 10px; | ||
} | ||
|
||
.settings-container .checkbox input:checked + label:after { | ||
left: calc(100% - 2px - 10px); | ||
} | ||
|
||
.settings-container .dropdown { | ||
padding: 4px 8px; | ||
font-size: 0.75rem; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
document.addEventListener('DOMContentLoaded', fetchLanguages); | ||
|
||
async function fetchLanguages() { | ||
try { | ||
const [languagesResponse, currentLanguageResponse] = await Promise.all([ | ||
fetch('/get-languages'), | ||
fetch('/get-locale') | ||
]); | ||
|
||
const languages = await languagesResponse.json(); | ||
const currentLanguage = await currentLanguageResponse.text(); | ||
|
||
const languageSelect = document.getElementById('language'); | ||
languages.forEach(lang => { | ||
const option = document.createElement('option'); | ||
option.value = lang; | ||
option.textContent = lang; | ||
languageSelect.appendChild(option); | ||
}); | ||
|
||
const savedLanguage = localStorage.getItem("language") || currentLanguage; | ||
setLanguageOnPageLoad(savedLanguage); | ||
} catch (error) { | ||
console.error("Failed to fetch languages or current language"); | ||
} | ||
} | ||
|
||
function setLanguageOnPageLoad(language) { | ||
document.getElementById("language").value = language; | ||
} | ||
|
||
function changeLanguage(lang) { | ||
fetch("/change-language", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ language: lang }), | ||
}).then((response) => { | ||
if (response.ok) { | ||
localStorage.setItem("language", lang); | ||
location.reload(); | ||
} else { | ||
console.error("Failed to change language"); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ curl_cffi | |
aiohttp | ||
flask | ||
flask_cors | ||
flask-babel | ||
streamlit | ||
selenium | ||
fake-useragent | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import subprocess | ||
from flask import request, session, jsonify | ||
from flask_babel import Babel | ||
|
||
|
||
def get_languages_from_dir(directory): | ||
"""Return a list of directory names in the given directory.""" | ||
return [name for name in os.listdir(directory) | ||
if os.path.isdir(os.path.join(directory, name))] | ||
|
||
|
||
BABEL_DEFAULT_LOCALE = 'en_US' | ||
BABEL_LANGUAGES = get_languages_from_dir('translations') | ||
|
||
|
||
def create_babel(app): | ||
"""Create and initialize a Babel instance with the given Flask app.""" | ||
babel = Babel(app) | ||
app.config['BABEL_DEFAULT_LOCALE'] = BABEL_DEFAULT_LOCALE | ||
app.config['BABEL_LANGUAGES'] = BABEL_LANGUAGES | ||
|
||
babel.init_app(app, locale_selector=get_locale) | ||
compile_translations() | ||
|
||
|
||
def get_locale(): | ||
"""Get the user's locale from the session or the request's accepted languages.""" | ||
return session.get('language') or request.accept_languages.best_match(BABEL_LANGUAGES) | ||
|
||
|
||
def get_languages(): | ||
"""Return a list of available languages in JSON format.""" | ||
return jsonify(BABEL_LANGUAGES) | ||
|
||
|
||
def compile_translations(): | ||
"""Compile the translation files.""" | ||
result = subprocess.run( | ||
['pybabel', 'compile', '-d', 'translations'], | ||
stdout=subprocess.PIPE, | ||
) | ||
|
||
if result.returncode != 0: | ||
raise Exception( | ||
f'Compiling translations failed:\n{result.stdout.decode()}') | ||
|
||
print('Translations compiled successfully') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.