diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 7f17c8c..3a9af94 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -1,20 +1,13 @@ -name: build plugin package - -on: - push: - pull_request: +name: package +on: push jobs: build: strategy: matrix: - # Use these Python versions - python: [ - 3.6 - ] - # and run on both Linux and Windows - os: [ubuntu-20.04, windows-2022] - runs-on: ${{matrix.os}} + python: [ 3.6 ] + os: [ ubuntu-20.04, windows-2022 ] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Setup python diff --git a/README.md b/README.md index 2b22f7c..04aed8f 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,24 @@ -# mcdr-translator +# 🌐 Simple Translator -[![license](https://img.shields.io/github/license/legendnightt/MCDR-Translator.svg)](https://github.com/legendnightt/MCDR-Translator/blob/master/LICENSE) -[![plugin package build status](https://github.com/legendnightt/MCDR-Translator/actions/workflows/package.yml/badge.svg?branch=master)](https://github.com/legendnightt/MCDR-Translator/actions/workflows/package.yml) -[![supported python versions](https://img.shields.io/badge/python->=%203.6%20-blue)](https://www.python.org/downloads) +[![license](https://img.shields.io/github/license/skuzow/simple-translator.svg)](https://github.com/skuzow/simple-translator/blob/master/LICENSE) +[![package](https://github.com/skuzow/simple-translator/actions/workflows/package.yml/badge.svg?branch=master)](https://github.com/skuzow/simple-translator/actions/workflows/package.yml) +[![python versions](https://img.shields.io/badge/python->=%203.6%20-blue)](https://www.python.org/downloads) -Really simple [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) plugin for translating text ingame, from all languages to `global_language`, and `secondary_language` to `global_language` automatically. +Really simple [MCDReforged](https://github.com/Fallen-Breath/MCDReforged) in-game translator plugin. More plugins in [MCDReforgedPluginsCatalogue](https://github.com/MCDReforged/PluginCatalogue/blob/catalogue/readme.md). -## How it works? +## 🗿 How it works? -Simply type `t what you want to translate`. +Basically translates from all languages to `global_language`, and `secondary_language` to `global_language`. -### Example: +To use it simply type: `t what you want to translate` -![example](https://raw.githubusercontent.com/legendnightt/MCDR-Translator/master/img/example.png) +example -## Required python modules +## 💾 Config -- [googletrans](https://pypi.org/project/googletrans/4.0.0rc1) == 4.0.0rc1 -- [mcdreforged](https://github.com/Fallen-Breath/MCDReforged) >= 1.2.0 - -To install them execute: -```bash -pip install googletrans==4.0.0rc1 mcdreforged -``` -Or download [requirements.txt](https://github.com/legendnightt/mcdr-translator/blob/master/requirements.txt), and execute: -```bash -pip install -r requirements.txt -``` - -## Config - -`config/translator.json` +Location: `config/simple_translator.json` ```json { @@ -40,3 +26,14 @@ pip install -r requirements.txt "secondary_language": "es" } ``` + +## 🗂️ Required Python libraries + +- [googletrans](https://pypi.org/project/googletrans/4.0.0rc1) == 4.0.0rc1 +- [mcdreforged](https://github.com/Fallen-Breath/MCDReforged) >= 1.2.0 + +To install them execute: + +```bash + pip install -r requirements.txt +``` diff --git a/img/example.png b/img/example.png deleted file mode 100644 index eab1325..0000000 Binary files a/img/example.png and /dev/null differ diff --git a/mcdreforged.plugin.json b/mcdreforged.plugin.json index f837408..eed232a 100644 --- a/mcdreforged.plugin.json +++ b/mcdreforged.plugin.json @@ -1,11 +1,15 @@ { - "id": "translator", - "version": "1.2.0", - "name": "Translator", - "description": "Translates text ingame", - "author": "legendnightt", - "link": "https://github.com/legendnightt/mcdr-translator", + "id": "simple_translator", + "version": "1.3.0", + "name": "SimpleTranslator", + "description": "In-game translator", + "author": "skuzow", + "link": "https://github.com/skuzow/simple-translator", + "dependencies": { + "mcdreforged": ">=2.1.0", + "googletrans": "==4.0.0rc1" + }, "resources": [ - "LICENSE" - ] + "LICENSE" + ] } diff --git a/requirements.txt b/requirements.txt index 80c4247..5e62193 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -mcdreforged +mcdreforged>=2.1.0 googletrans==4.0.0rc1 diff --git a/translator/__init__.py b/simple_translator/__init__.py similarity index 62% rename from translator/__init__.py rename to simple_translator/__init__.py index b0eda03..6162cef 100644 --- a/translator/__init__.py +++ b/simple_translator/__init__.py @@ -4,7 +4,7 @@ from googletrans import Translator from mcdreforged.api.all import * -PLUGIN_METADATA = ServerInterface.get_instance().as_plugin_server_interface().get_self_metadata() +plugin_metadata = ServerInterface.get_instance().as_plugin_server_interface().get_self_metadata() class Config(Serializable): @@ -13,15 +13,13 @@ class Config(Serializable): config: Optional[Config] = None -translator = Translator() -prefix = 'Translator (t )' -plugin_name = PLUGIN_METADATA.name server_inst: PluginServerInterface +translator = Translator() -def auto_translator(msg: str): - return translator.translate(msg, dest=config.secondary_language).text if translator.detect( - msg).lang == config.global_language else translator.translate(msg, dest=config.global_language).text +def auto_translator(message: str): + return translator.translate(message, dest=config.secondary_language).text if translator.detect(message).\ + lang == config.global_language else translator.translate(message, dest=config.global_language).text def on_user_info(server: ServerInterface, info: Info): @@ -33,13 +31,14 @@ def on_load(server: PluginServerInterface, old): global server_inst server_inst = server load_config(None) - help_message = f'Use t and space, then what you want to translate, {config.global_language.upper()} to ' \ - f'{config.secondary_language.upper()} & ALL LANGUAGES to {config.global_language.upper()} auto' + prefix = 't translate-text' + help_message = f'Use t and space, then what you want to translate, works from {config.global_language} to ' \ + f'{config.secondary_language} & all languages to {config.global_language}' server.register_help_message(prefix, help_message) def load_config(source: Optional[CommandSource]): global config, server_inst - config_file_path = os.path.join('config', '{}.json'.format(PLUGIN_METADATA.id)) + config_file_path = os.path.join('config', '{}.json'.format(plugin_metadata.id)) config = server_inst.load_config_simple(config_file_path, in_data_folder=False, source_to_reply=source, echo_in_console=False, target_class=Config)