Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Add translations. (read README.md in /translations)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-victor committed Jul 26, 2023
2 parents e4590e3 + a788897 commit e0d3bea
Show file tree
Hide file tree
Showing 34 changed files with 1,871 additions and 410 deletions.
26 changes: 14 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM python:3.10-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
FROM python:3.10-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt

RUN python -m venv venv
ENV PATH="/app/venv/bin:$PATH"

RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential libffi-dev cmake libcurl4-openssl-dev && \
pip3 install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python3", "./run.py"]
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential libffi-dev cmake libcurl4-openssl-dev && \
pip3 install --no-cache-dir -r requirements.txt

COPY . .

RUN chmod -R 777 translations

CMD ["python3", "./run.py"]
48 changes: 27 additions & 21 deletions server/babel.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
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 = [
'en_US',
'es_MX',
'pt_BR',
'ru_RU',
'zh_CN',
'zh_TW',
'fr_FR',
'de_DE',
'it_IT',
'ja_JP',
'ko_KR',
'ar_SA',
'hi_IN',
'tr_TR',
]
BABEL_LANGUAGES = get_languages_from_dir('translations')


def create_babel(app):
Expand All @@ -27,16 +21,28 @@ def create_babel(app):
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."""
user_language = session.get('language')
if user_language is not None:
return user_language

return request.accept_languages.best_match(BABEL_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')
67 changes: 67 additions & 0 deletions translations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Contributing to Translations for FreeGPT WebUI 🌐

This README.md file was created to guide contributors on how to contribute translations to the FreeGPT WebUI project. The translations are located in the `translations` folder and are generated by `babel-flask`.

## Modifying an existing translation

To modify an existing translation, follow the steps below:

1. Inside the `translations` folder, you will find all existing translations in the project.

2. Translate the strings in the `.po` file found within the folder of the language translation you want to modify. <br>
The identifiers of the strings to be translated are in the format `msgid "string"` and should be translated in the `msgstr ""` field. For example:

```
msgid "New Conversation"
msgstr "Nova Conversa"
```

3. Add your name and GitHub profile to the "Contributors" section at the beginning of the `.po` file. If there are already contributors, add your name to the list. For example:

```
# Portuguese (Brazil) translations for FreeGPT WebUI.
# Copyright (C) 2023 FreeGPT WebUI.
# This file is distributed under the same license as the FreeGPT WebUI
# project.
# Contributors:
# Ramon - github.com/ramonvc/
# Your Name - github.com/yourprofile/
# ...
```

4. Create a pull request with the changes so we can review and incorporate them into the project.

## Adding a new language

To add a new language, follow the steps below:

1. Install `babel-flask` (if not already installed) using the command `pip install Flask-Babel`.

2. Inside the project folder use the following code to generate the folder with the translation template, replacing LANGUAGE_CODE with the language code. Example: en_US

```
pybabel init -i ./translations/messages.pot -d translations -l LANGUAGE_CODE
```

3. Translate the strings in the created `.po` file. The identifiers of the strings to be translated are in the format `msgid "string"` and should be translated in the `msgstr ""` field. For example:

```
msgid "New Conversation"
msgstr "Nova Conversa"
```

4. Add your name and GitHub profile to the "Contributors" section at the beginning of the `.po` file. For example:

```
# Portuguese (Brazil) translations for FreeGPT WebUI.
# Copyright (C) 2023 FreeGPT WebUI.
# This file is distributed under the same license as the FreeGPT WebUI
# project.
# Contributors:
# Ramon - github.com/ramonvc/
# ...
```

5. Create a pull request with the changes so we can review and incorporate them into the project.


64 changes: 31 additions & 33 deletions translations/ar_SA/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,68 @@
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: https://github.com/ramonvc/freegpt-webui"
"/issuesMIME-Version: 1.0\n"
"POT-Creation-Date: 2023-07-24 21:10-0300\n"
"PO-Revision-Date: 2023-07-24 21:10-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Report-Msgid-Bugs-To: https://github.com/ramonvc/freegpt-webui/issues"
"MIME-Version: 1.0\n"
"Language: ar_SA\n"
"Language-Team: ar_SA <[email protected]>\n"
"Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : "
"n%100>=3 && n%100<=10 ? 3 : n%100>=0 && n%100<=2 ? 4 : 5);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"

#: client/html/index.html:42
#:
msgid "New Conversation"
msgstr ""
msgstr "محادثة جديدة"

#: client/html/index.html:49
#:
msgid "Clear Conversations"
msgstr ""
msgstr "مسح المحادثات"

#: client/html/index.html:54
#:
msgid "API Key"
msgstr ""
msgstr "مفتاح API"

#: client/html/index.html:57
#:
msgid "Ok"
msgstr ""
msgstr "حسنا"

#: client/html/index.html:61
#:
msgid "Dark Mode"
msgstr ""
msgstr "الوضع الداكن"

#: client/html/index.html:66
#:
msgid "Language"
msgstr ""
msgstr "اللغة"

#: client/html/index.html:89
#:
msgid "Stop Generating"
msgstr ""
msgstr "توقف عن التوليد"

#: client/html/index.html:97
#:
msgid "Ask a question"
msgstr ""
msgstr "اسأل سؤال"

#: client/html/index.html:131
#:
msgid "IMAGE"
msgstr ""
msgstr "صورة"

#: client/html/index.html:138
#:
msgid "Default"
msgstr ""
msgstr "افتراضي"

#: client/html/index.html:139
#:
msgid "DAN"
msgstr ""
msgstr "دان"

#: client/html/index.html:140
#:
msgid "Evil"
msgstr ""
msgstr "شرير"

#: client/html/index.html:147
#:
msgid "Web Access"
msgstr ""
msgstr "الوصول إلى الويب"

#:
msgid "Version"
msgstr "الإصدار"
74 changes: 74 additions & 0 deletions translations/cs_CZ/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Czech (Czechia) translations for FreeGPT WebUI.
# Copyright (C) 2023 FreeGPT WebUI.
# This file is distributed under the same license as the FreeGPT WebUI
# project.
# Contributors:
# example name - github.com/example/
# example name2 - github.com/example2/
#
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: https://github.com/ramonvc/freegpt-webui/issues"
"MIME-Version: 1.0\n"
"Language: cs_CZ\n"
"Language-Team: cs_CZ <[email protected]>\n"
"Plural-Forms: nplurals=3; plural=((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"

#:
msgid "New Conversation"
msgstr "Nová konverzace"

#:
msgid "Clear Conversations"
msgstr "Vymazat konverzace"

#:
msgid "API Key"
msgstr "API klíč"

#:
msgid "Ok"
msgstr "Dobře"

#:
msgid "Dark Mode"
msgstr "Tmavý režim"

#:
msgid "Language"
msgstr "Jazyk"

#:
msgid "Stop Generating"
msgstr "Zastavit generování"

#:
msgid "Ask a question"
msgstr "Zeptejte se na otázku"

#:
msgid "IMAGE"
msgstr "OBRAZ"

#:
msgid "Default"
msgstr "Výchozí"

#:
msgid "DAN"
msgstr "DAN"

#:
msgid "Evil"
msgstr "Zlo"

#:
msgid "Web Access"
msgstr "Webový přístup"

#:
msgid "Version"
msgstr "Verze"
Loading

0 comments on commit e0d3bea

Please sign in to comment.