├── .github └── workflows │ └── python-publish.yml ├── LICENSE ├── MANIFEST.in ├── README.md ├── __init__.py ├── flet_translator ├── __init__.py ├── __pycache__ │ └── __init__.cpython-311.pyc ├── tools │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-311.pyc │ │ ├── translate_control_content.cpython-311.pyc │ │ ├── translate_page.cpython-311.pyc │ │ ├── translate_using_google.cpython-311.pyc │ │ └── translate_using_opusMT.cpython-311.pyc │ ├── translate_control_content.py │ ├── translate_page.py │ ├── translate_using_google.py │ └── translate_using_opusMT.py └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-311.pyc │ ├── allowed_props_to_translate.cpython-311.pyc │ ├── google_supported_langaues.cpython-311.pyc │ ├── is_rtl.cpython-311.pyc │ └── opusMT_supported_languages.cpython-311.pyc │ ├── allowed_props_to_translate.py │ ├── google_supported_langaues.py │ ├── is_rtl.py │ └── opusMT_supported_languages.py ├── pyproject.toml ├── setup.py └── test.py /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package using Twine when a release is created 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Upload Python Package 10 | 11 | on: 12 | release: 13 | types: [published] 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | deploy: 20 | 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - uses: actions/checkout@v3 25 | - name: Set up Python 26 | uses: actions/setup-python@v3 27 | with: 28 | python-version: '3.x' 29 | - name: Install dependencies 30 | run: | 31 | python -m pip install --upgrade pip 32 | pip install build 33 | - name: Build package 34 | run: python -m build 35 | - name: Publish package 36 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 37 | with: 38 | user: __token__ 39 | password: ${{ secrets.PYPI_API_TOKEN }} 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include flet_translator/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flet_translator 2 | 3 | **flet_tranlator**, An easy-to-use package for make your flet app support multiple languages without effecting any of your original flet code! Code your app in your native language like for example German, then with one simple line of code your app will be ready in any of your target language, English, France or Arabic you say it!!. 4 | 5 | ## Installation 6 | 7 | You can install `flet_translator` using pip: 8 | 9 | ```bash 10 | pip install flet_translator --upgrade 11 | ``` 12 | 13 | ## Example and Usage 14 | There is two modes of translation with this package. The first one is with `use_internet = True`, this will use Google Translation API for all translation requests. The second one is with `use_internet = False` this will use a local Machine learning translation model for all translation requests. 15 | 16 | 17 | This is an example usage of using `TranslateFletPage` class with Google translation API: 18 | ```python 19 | from flet_translator import TranslateFletPage, GoogleTranslateLanguage 20 | import flet 21 | 22 | def main(page: flet.Page): 23 | # Create a TranslateFletPage instance 24 | tp = TranslateFletPage(page=page, into_language=GoogleTranslateLanguage.turkish, use_internet=True) 25 | 26 | c = flet.Container(content=flet.Text("I will be Turkish!")) 27 | page.add(c) 28 | 29 | # This will update the translations and page at the same time. 30 | tp.update() 31 | 32 | 33 | flet.app(target=main) 34 | ``` 35 | 36 | This is an example of using `TranslateFletPage` class with local translation model: 37 | ```python 38 | from flet_translator import TranslateFletPage, OpusmtLanguage 39 | import flet 40 | 41 | def main (page:flet.Page): 42 | # Create a TranslateFletPage instance 43 | tp = TranslateFletPage(page=page, into_language=OpusmtLanguage.ar, use_internet=False) 44 | 45 | c = flet.Container(content=flet.Text("I will be Arabic!")) 46 | page.add(c) 47 | 48 | # This will update the translations and page at the same time. 49 | tp.update() 50 | 51 | flet.app(target=main) 52 | ``` 53 | Its really simple and easy 😃! 54 | 55 | ## `TranslateFletPage` properties 56 | - `use_internet` (You can set this once with the --init--): If you set this to `True`, then all translation requests will be using Google translation API. But if you set it to `False` then all the translation requests will be using the local machine learning that trained for translating. 57 | - `from_language`: The main language, the language that are the contents written with. With `use_internet = True` you can set this to `GoogleTranslateLanguage.auto`. 58 | - `skiped_controls.append (control)`: A property list containing all controls you choose that will be skipped as they will not be translated. 59 | - `into_language`: The target langauge, the language that the app should be translated to. 60 | - `activate_google_translation()`: A function property for switching the translation mode into `use_internet = True`. 61 | - `activate_local_ML_translation()`: A function property for switching the translation mode into `use_internet = False`. 62 | 63 | # suggestions 64 | While using Google API for translating can be stable if you have a stable internet, trusted results and fast. But it needs internet, also google servers may give you a temporarily block if you did spam the translation requests. 65 | 66 | The local ML translation model is also can be reliable and fast and super stable. But it takes a storage in the client side, also it need a device performence for translating the app. 67 | 68 | So the best choice for you can depend on the project app needs and requirements. I think if your flet app is a website and it run on a server side, then using the local machine learning will be much better as your server is have a good performence and will expect multiple translation requests. -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/__init__.py -------------------------------------------------------------------------------- /flet_translator/__init__.py: -------------------------------------------------------------------------------- 1 | from .tools.translate_page import TranslateFletPage 2 | from .utils.google_supported_langaues import GoogleTranslateLanguage 3 | from .utils.opusMT_supported_languages import OpusmtLanguage -------------------------------------------------------------------------------- /flet_translator/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/tools/__init__.py -------------------------------------------------------------------------------- /flet_translator/tools/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/tools/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/tools/__pycache__/translate_control_content.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/tools/__pycache__/translate_control_content.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/tools/__pycache__/translate_page.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/tools/__pycache__/translate_page.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/tools/__pycache__/translate_using_google.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/tools/__pycache__/translate_using_google.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/tools/__pycache__/translate_using_opusMT.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/tools/__pycache__/translate_using_opusMT.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/tools/translate_control_content.py: -------------------------------------------------------------------------------- 1 | from ..utils.allowed_props_to_translate import allowed_props_to_translate 2 | from ..tools.translate_using_google import translate_using_google 3 | from ..tools.translate_using_opusMT import translate_using_opusMT 4 | import flet, threading, asyncio 5 | 6 | 7 | def translate_control_content (TranslateFletPage_class, control:flet.Control, use_internet:bool=True, update_async=False): 8 | """ 9 | This function translate the control content. 10 | 11 | It create an attr (last_translated_texts:dict) in the control that stores the last translated 12 | texts so it reduces unnecessary translation requests. 13 | """ 14 | 15 | # Check if the control is skiped so not translate it. 16 | if control in TranslateFletPage_class.skiped_controls: return 17 | if isinstance(control, flet.TextField): return 18 | if control == None: return 19 | 20 | # start translating the control 21 | for p in allowed_props_to_translate: 22 | if hasattr(control, str(p)): 23 | value = getattr(control, str(p)) 24 | if use_internet and value != None: 25 | r = translate_using_google( 26 | src=value, 27 | from_language=TranslateFletPage_class.from_language.value, 28 | into_language=TranslateFletPage_class.into_language.value 29 | ) 30 | setattr(control, str(p), str(r)) 31 | 32 | elif use_internet == False and value != None: 33 | r = translate_using_opusMT( 34 | Translatemodel=TranslateFletPage_class.opusMT_model, 35 | src=value, 36 | from_language=TranslateFletPage_class.from_language.value, 37 | into_language=TranslateFletPage_class.into_language.value 38 | ) 39 | setattr(control, str(p), str(r)) 40 | 41 | 42 | 43 | sub_controls_names = ["controls", "tabs", "actions"] 44 | for i in sub_controls_names: 45 | if hasattr(control, i): 46 | for i in getattr(control, str(i)): 47 | threading.Thread(target=translate_control_content, kwargs={ 48 | "TranslateFletPage_class" : TranslateFletPage_class, 49 | "control" : i, 50 | "use_internet" : use_internet 51 | }, daemon=True).start() 52 | # translate_control_content(TranslateFletPage_class, i, use_internet) 53 | 54 | sub_contents_names = ["content", "leading", "title"] 55 | for ic in sub_contents_names: 56 | if hasattr(control, ic): 57 | threading.Thread(target=translate_control_content, kwargs={ 58 | "TranslateFletPage_class" : TranslateFletPage_class, 59 | "control" : getattr(control, ic), 60 | "use_internet" : use_internet 61 | }, daemon=True).start() 62 | 63 | if control.page != None: 64 | if update_async: 65 | asyncio.create_task(control.update_async()) 66 | else: 67 | control.update() -------------------------------------------------------------------------------- /flet_translator/tools/translate_page.py: -------------------------------------------------------------------------------- 1 | from ..utils.google_supported_langaues import GoogleTranslateLanguage 2 | from ..utils.is_rtl import is_rtl_language 3 | from ..tools.translate_control_content import translate_control_content 4 | import flet, threading, os, asyncio 5 | 6 | 7 | class TranslateFletPage: 8 | """ 9 | This class will translate the whole page into a specific language. 10 | The childs controls, page info (title, appbar, ..), etc.. 11 | 12 | if `use_internet` is True (Which is not recomended for some cases), That mean 13 | the translate model is Google translate API, which may give you block band for spam requests. 14 | 15 | if `use_internet` is False, Thats mean the translate model is `opus-mt`, which is a 16 | local machine learning that trained for many popular languages. It works localy on the device, 17 | Its use the device performance. So it can lead to a heavy usage. 18 | """ 19 | def __init__(self, 20 | page : flet.Page, 21 | use_internet = True, 22 | from_language = GoogleTranslateLanguage.auto, 23 | into_language = GoogleTranslateLanguage.auto, 24 | skiped_controls = None 25 | ) -> None: 26 | 27 | self.page = page 28 | self.from_language = from_language 29 | self.into_language = into_language 30 | 31 | if isinstance(skiped_controls, list): 32 | self.skiped_controls = skiped_controls 33 | else: 34 | self.skiped_controls = [] 35 | 36 | self.__use_internet = use_internet 37 | 38 | if use_internet == False: 39 | try: 40 | from easynmt import EasyNMT 41 | except: 42 | raise ImportError("Please install the easynmt package:\npip install EasyNMT") 43 | # store ML models 44 | self.opusMT_model = EasyNMT('opus-mt') 45 | 46 | # Activate the model to be faster in the second request. 47 | self.opusMT_model.translate( 48 | "Hi", 49 | target_lang="en", 50 | source_lang="en" 51 | ) 52 | 53 | 54 | 55 | def translate_child_controls (self, update_in_async:bool): 56 | if self.page.appbar != None: 57 | translate_control_content(self, control=self.page.appbar, use_internet=self.__use_internet, update_async=update_in_async) 58 | 59 | if self.page.dialog != None: 60 | translate_control_content(self, control=self.page.dialog, use_internet=self.__use_internet, update_async=update_in_async) 61 | 62 | if self.page.banner != None: 63 | translate_control_content(self, control=self.page.banner, use_internet=self.__use_internet, update_async=update_in_async) 64 | 65 | if self.page.snack_bar != None: 66 | translate_control_content(self, control=self.page.snack_bar, use_internet=self.__use_internet, update_async=update_in_async) 67 | 68 | if update_in_async: 69 | for con in self.page.controls: 70 | translate_control_content(self, con, self.__use_internet, update_in_async) 71 | else: 72 | for con in self.page.controls: 73 | threading.Thread( 74 | target=translate_control_content, 75 | args=[self], 76 | kwargs={ 77 | "control" : con, 78 | "use_internet" : self.__use_internet, 79 | "update_async" : update_in_async 80 | } 81 | ).start() 82 | 83 | def activate_local_ML_translation (self): 84 | """This will activate the local machine learning model to be used in future translation requests""" 85 | try: 86 | from easynmt import EasyNMT 87 | except: 88 | raise ImportError("Please install the easynmt package:\npip install EasyNMT") 89 | self.__use_internet = False 90 | # store ML models 91 | self.opusMT_model = EasyNMT('opus-mt') 92 | 93 | # Activate the model to be faster in the second request. 94 | self.opusMT_model.translate( 95 | "Hi", 96 | target_lang="en", 97 | source_lang="en" 98 | ) 99 | 100 | 101 | def activate_google_translation (self): 102 | """This will activate the google translation mode, so any future translation requests will be via google API""" 103 | self.__use_internet = True 104 | 105 | 106 | def update(self): 107 | """This will be called per page.update so it follow the page updates""" 108 | if is_rtl_language(language=str(self.into_language.value)): 109 | self.page.rtl = True 110 | else: 111 | self.page.rtl = False 112 | self.page.update() 113 | 114 | self.translate_child_controls(update_in_async=False) 115 | self.page.update() 116 | 117 | async def update_async (self): 118 | """This will be called per page.update so it follow the page updates""" 119 | if is_rtl_language(language=str(self.into_language.value)): 120 | self.page.rtl = True 121 | else: 122 | self.page.rtl = False 123 | await self.page.update_async() 124 | 125 | self.translate_child_controls(update_in_async=True) 126 | await self.page.update_async() -------------------------------------------------------------------------------- /flet_translator/tools/translate_using_google.py: -------------------------------------------------------------------------------- 1 | from deep_translator import GoogleTranslator 2 | 3 | 4 | 5 | def translate_using_google (src:str, from_language:str, into_language:str): 6 | sents = [] 7 | 8 | current_sent = "" 9 | num = 0 10 | for i in src: 11 | if num >= 250: 12 | sents.append(current_sent) 13 | current_sent = "" 14 | num = 0 15 | current_sent = current_sent + i 16 | num = num + 1 17 | 18 | sents.append(current_sent) 19 | res = GoogleTranslator(source=from_language, target=into_language).translate_batch(sents) 20 | 21 | full_res = "" 22 | for i in res: 23 | full_res = full_res + i 24 | 25 | return str(full_res) -------------------------------------------------------------------------------- /flet_translator/tools/translate_using_opusMT.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | def translate_using_opusMT (Translatemodel, src:str, from_language, into_language): 5 | try: 6 | from easynmt import EasyNMT 7 | except: 8 | raise ImportError("Please install the easynmt package:\npip install EasyNMT") 9 | if from_language == "auto": 10 | r = Translatemodel.translate(src, target_lang=into_language, 11 | perform_sentence_splitting=True) 12 | else: 13 | r = Translatemodel.translate(src, target_lang=into_language, source_lang=from_language, 14 | perform_sentence_splitting=True) 15 | 16 | return str(r) 17 | 18 | 19 | if __name__ == "__main__": 20 | from easynmt import EasyNMT 21 | model = EasyNMT('opus-mt') -------------------------------------------------------------------------------- /flet_translator/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/utils/__init__.py -------------------------------------------------------------------------------- /flet_translator/utils/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/utils/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/utils/__pycache__/allowed_props_to_translate.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/utils/__pycache__/allowed_props_to_translate.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/utils/__pycache__/google_supported_langaues.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/utils/__pycache__/google_supported_langaues.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/utils/__pycache__/is_rtl.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/utils/__pycache__/is_rtl.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/utils/__pycache__/opusMT_supported_languages.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SKbarbon/flet_translator/0185efdd8138a9f2d02102cad3638146f296a2e2/flet_translator/utils/__pycache__/opusMT_supported_languages.cpython-311.pyc -------------------------------------------------------------------------------- /flet_translator/utils/allowed_props_to_translate.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | allowed_props_to_translate = [ 7 | "value", "label", "tooltip", "text", "semantics_label" 8 | ] -------------------------------------------------------------------------------- /flet_translator/utils/google_supported_langaues.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | 4 | class GoogleTranslateLanguage (Enum): 5 | """These are the lanuages that supported with google translate""" 6 | auto = "auto" 7 | afrikaans = "afrikaans" 8 | albanian = "albanian" 9 | amharic = "amharic" 10 | arabic = "arabic" 11 | armenian = "armenian" 12 | assamese = "assamese" 13 | aymara = "aymara" 14 | azerbaijani = "azerbaijani" 15 | bambara = "bambara" 16 | basque = "basque" 17 | belarusian = "belarusian" 18 | bengali = "bengali" 19 | bhojpuri = "bhojpuri" 20 | bosnian = "bosnian" 21 | bulgarian = "bulgarian" 22 | catalan = "catalan" 23 | cebuano = "cebuano" 24 | chichewa = "chichewa" 25 | chinese_simplified = "chinese (simplified)" 26 | chinese_traditional = "chinese (traditional)" 27 | corsican = "corsican" 28 | croatian = "croatian" 29 | czech = "czech" 30 | danish = "danish" 31 | dhivehi = "dhivehi" 32 | dogri = "dogri" 33 | dutch = "dutch" 34 | english = "english" 35 | esperanto = "esperanto" 36 | estonian = "estonian" 37 | ewe = "ewe" 38 | filipino = "filipino" 39 | finnish = "finnish" 40 | french = "french" 41 | frisian = "frisian" 42 | galician = "galician" 43 | georgian = "georgian" 44 | german = "german" 45 | greek = "greek" 46 | guarani = "guarani" 47 | gujarati = "gujarati" 48 | haitian_creole = "haitian creole" 49 | hausa = "hausa" 50 | hawaiian = "hawaiian" 51 | hebrew = "hebrew" 52 | hindi = "hindi" 53 | hmong = "hmong" 54 | hungarian = "hungarian" 55 | icelandic = "icelandic" 56 | igbo = "igbo" 57 | ilocano = "ilocano" 58 | indonesian = "indonesian" 59 | irish = "irish" 60 | italian = "italian" 61 | japanese = "japanese" 62 | javanese = "javanese" 63 | kannada = "kannada" 64 | kazakh = "kazakh" 65 | khmer = "khmer" 66 | kinyarwanda = "kinyarwanda" 67 | konkani = "konkani" 68 | korean = "korean" 69 | krio = "krio" 70 | kurdish_kurmanji = "kurdish (kurmanji)" 71 | kurdish_sorani = "kurdish (sorani)" 72 | kyrgyz = "kyrgyz" 73 | lao = "lao" 74 | latin = "latin" 75 | latvian = "latvian" 76 | lingala = "lingala" 77 | lithuanian = "lithuanian" 78 | luganda = "luganda" 79 | luxembourgish = "luxembourgish" 80 | macedonian = "macedonian" 81 | maithili = "maithili" 82 | malagasy = "malagasy" 83 | malay = "malay" 84 | malayalam = "malayalam" 85 | maltese = "maltese" 86 | maori = "maori" 87 | marathi = "marathi" 88 | meiteilon_manipuri = "meiteilon (manipuri)" 89 | mizo = "mizo" 90 | mongolian = "mongolian" 91 | myanmar = "myanmar" 92 | nepali = "nepali" 93 | norwegian = "norwegian" 94 | odia_oriya = "odia (oriya)" 95 | oromo = "oromo" 96 | pashto = "pashto" 97 | persian = "persian" 98 | polish = "polish" 99 | portuguese = "portuguese" 100 | punjabi = "punjabi" 101 | quechua = "quechua" 102 | romanian = "romanian" 103 | russian = "russian" 104 | samoan = "samoan" 105 | sanskrit = "sanskrit" 106 | scots_gaelic = "scots gaelic" 107 | sepedi = "sepedi" 108 | serbian = "serbian" 109 | sesotho = "sesotho" 110 | shona = "shona" 111 | sindhi = "sindhi" 112 | sinhala = "sinhala" 113 | slovak = "slovak" 114 | slovenian = "slovenian" 115 | somali = "somali" 116 | spanish = "spanish" 117 | sundanese = "sundanese" 118 | swahili = "swahili" 119 | swedish = "swedish" 120 | tajik = "tajik" 121 | tamil = "tamil" 122 | tatar = "tatar" 123 | telugu = "telugu" 124 | thai = "thai" 125 | tigrinya = "tigrinya" 126 | tsonga = "tsonga" 127 | turkish = "turkish" 128 | turkmen = "turkmen" 129 | twi = "twi" 130 | ukrainian = "ukrainian" 131 | urdu = "urdu" 132 | uyghur = "uyghur" 133 | uzbek = "uzbek" 134 | vietnamese = "vietnamese" 135 | welsh = "welsh" 136 | xhosa = "xhosa" 137 | yiddish = "yiddish" 138 | yoruba = "yoruba" 139 | zulu = "zulu" -------------------------------------------------------------------------------- /flet_translator/utils/is_rtl.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | def is_rtl_language (language:str): 5 | all_RTLs = [ 6 | "arabic", "hebrew", "persian (farsi)", "pashto", "sindhi", "dhivehi", 7 | "kurdish (kurmanji)", "uyghur", "yiddish", "ar", "he", "fa", "ps", "sd", "dv", 8 | "ku", "ug", "yi" 9 | ] 10 | 11 | if str(language) in all_RTLs: 12 | return True 13 | 14 | return False -------------------------------------------------------------------------------- /flet_translator/utils/opusMT_supported_languages.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | 4 | class OpusmtLanguage (Enum): 5 | """ 6 | This class contain all languages supported with OpusMT ML translate. 7 | 8 | Its better with Opusmt to not use `auto` 9 | """ 10 | auto = "auto" 11 | af = "af" 12 | ar = "ar" 13 | az = "az" 14 | bn = "bn" 15 | cs = "cs" 16 | de = "de" 17 | en = "en" 18 | es = "es" 19 | et = "et" 20 | fa = "fa" 21 | fi = "fi" 22 | fr = "fr" 23 | gl = "gl" 24 | gu = "gu" 25 | he = "he" 26 | hi = "hi" 27 | hr = "hr" 28 | id_language = "id" 29 | it_language = "it" 30 | ja = "ja" 31 | ka = "ka" 32 | kk = "kk" 33 | km = "km" 34 | ko = "ko" 35 | lt = "lt" 36 | lv = "lv" 37 | ml = "ml" 38 | mn = "mn" 39 | my = "my" 40 | ne = "ne" 41 | nl = "nl" 42 | pl = "pl" 43 | ps = "ps" 44 | pt = "pt" 45 | ro = "ro" 46 | ru = "ru" 47 | si = "si" 48 | sl = "sl" 49 | sv = "sv" 50 | sw = "sw" 51 | ta = "ta" 52 | th = "th" 53 | tl = "tl" 54 | tr = "tr" 55 | uk = "uk" 56 | ur = "ur" 57 | vi = "vi" 58 | xh = "xh" 59 | zh = "zh" -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=54", 4 | "wheel" 5 | ] 6 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open("README.md", encoding="utf-8") as f: 4 | long_des = str(f.read()) 5 | 6 | setup( 7 | name='flet_translator', 8 | version='1.2.7', 9 | author='SKbarbon', 10 | description='A package that help flet developers to make their apps support multiple languages', 11 | long_description=long_des, 12 | long_description_content_type='text/markdown', 13 | url='https://github.com/SKbarbon/flet_translator', 14 | install_requires=["flet", "sacremoses", "deep-translator"], 15 | packages=find_packages(), 16 | classifiers=[ 17 | "Programming Language :: Python :: 3", 18 | "Operating System :: MacOS :: MacOS X", 19 | "Operating System :: Microsoft :: Windows" 20 | ], 21 | ) -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | from flet_translator import TranslateFletPage, GoogleTranslateLanguage, OpusmtLanguage 2 | import flet 3 | 4 | async def main(page:flet.Page): 5 | tp = TranslateFletPage(page=page, into_language=GoogleTranslateLanguage.arabic, use_internet=True) 6 | 7 | t = flet.Text("Hello, world!") 8 | await page.add_async(t) 9 | 10 | await tp.update_async() 11 | print("Done") 12 | await tp.update_async() 13 | 14 | flet.app(target=main) --------------------------------------------------------------------------------