Skip to content

Commit

Permalink
Merge pull request #3 from skuzow/develop
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
skuzow authored Jul 2, 2022
2 parents 37968f5 + 2b428e4 commit 3fac0f1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 56 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 22 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
# 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)
<img src="https://user-images.githubusercontent.com/61398114/177015561-606cfec3-78be-4a16-9846-40388561618e.png" alt="example" width="650"/>

## 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
{
"global_language": "en",
"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
```
Binary file removed img/example.png
Binary file not shown.
20 changes: 12 additions & 8 deletions mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mcdreforged
mcdreforged>=2.1.0
googletrans==4.0.0rc1
19 changes: 9 additions & 10 deletions translator/__init__.py → simple_translator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)

0 comments on commit 3fac0f1

Please sign in to comment.