Giter Site home page Giter Site logo

tkarabela / translate-swf Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 13 KB

Japanese-to-English translation tool for SWF (Adobe Flash) files

License: MIT License

Python 100.00%
translation swf flash machine-translation microsoft-azure microsoft-cognitive-services adobe-flash japanese

translate-swf's Introduction

pyTranslateSwf

Japanese-to-English translation tool for SWF (Adobe Flash) files

This Python tool can be used to extract strings from SWF assets for translation, do the translation itself (cloud-based or offline), and write translated strings back to the assets. You will also need the open-source JPEXS Flash Decompiler to move assets in and out of the SWF file.

pyTranslateSwf is licensed under the MIT license (see LICENSE.txt).

Installation

You will need Python 3.6+ and the following libraries:

...if you wish to use Microsoft Azure translation service (recommended):

pip install regex uuid requests

...if you wish to use the provided offline translator:

pip install regex jamdict stanza

Quickstart

We will be using the JPEXS Flash Decompiler and translateSfw.py script to interact with the library. You can use -h to get help: translateSfw.py -h or translateSfw.py translate -h.

1) Export assets from SWF file

  • Download the JPEXS Flash Decompiler and open your SWF file in the GUI.
  • In the asset tree, select the texts and scripts folders and click the Export Selection button in the ribbon above. Make sure to export text as "Plain Text" and scripts as "ActionScript".
  • Save the assets into a directory (this will be your working directory, it should now have texts and scripts subdirectories).

2) Gather strings for translation

In your working directory, run the following:

translateSfw.py gather

This will generate a JSON file with all the (unique) extracted strings, ready for translation. Note that this is unlikely to extract 100% of the texts, notably texts saved as bitmap/vector graphics and any string literals in ActionScript which the heuristic missed.

3) Run machine translation (optional)

If you are using Microsoft Azure (recommended), run the following:

translateSfw.py translate azure --azure-subscription-key <YOUR-KEY> --azure-subscription-region <YOUR-REGION>

You can also use the offline translation backend (which will generate much lower quality text):

translateSfw.py translate offline

4) Export translated strings back into assets

In your working directory, run the following:

translateSfw.py export

This will modify the assets with the new strings. Do not run gather or export again after doing this, as the script would get confused by the new strings in assets. If you wish to do something differently, delete the assets and start again by export them (see Step 1).

5) Import new assets and generate SWF file

  • Assuming you still have JPEXS Flash Decompiler window open with your original SWF loaded, click the Import Text and Import Scripts buttons in the ribbon above to load your modified assets from the working directory.
  • When this is done, click Save As... in the ribbon and generate your translated SWF file.

Translation backends

Currently, there are two available backends for machine translation: Microsoft Azure Cognitive Services Translator (cloud-based, "proper" machine translation) and custom offline solution (dictionary-based, marginally usable). It's recommended to use Microsoft Azure if possible - you will need a subscription key to do that.

Input text Translation (Microsoft Azure) Translation (offline translator)
こんにちは世界 Hello world KONNICHI HA the world

Additionally, you can skip the machine translation step and translate the extracted strings yourself. They are stored as JSON.

Diving into the library

The Translator subclasses are used as follows:

from pyTranslateSwf import OfflineTranslator, MicrosoftAzureTranslator

translator = OfflineTranslator()
input_strings = ["こんにちは世界"]
output_strings = translator.translate_all(input_strings)
print(output_strings[0])

The Parser subclasses are used as follows:

from pyTranslateSwf import JPEXSActionScriptParser, JPEXSPlainTextParser

parser = JPEXSActionScriptParser("./scripts/test.as")
input_strings = parser.get_extracted_strings()
output_strings = [my_translate_function(s) for s in input_strings]
parser.replace_strings(output_strings)
parser.save()

Refer to module and class docstrings for more info.

translate-swf's People

Contributors

tkarabela avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alimsoftware

translate-swf's Issues

SyntaxError: invalid syntax

C:\Users\bnico\Desktop\redacted>translateSfw.py gather
Traceback (most recent call last):
File "C:\Users\bnico\Desktop\redacted\translateSfw.py", line 2, in
import pyTranslateSwf
File "C:\Users\bnico\Desktop\redacted\pyTranslateSwf_init_.py", line 14, in
from .parsers import Parser, JPEXSPlainTextParser, JPEXSActionScriptParser, get_parsers_for_directory
File "C:\Users\bnico\Desktop\redacted\pyTranslateSwf\parsers.py", line 53
def init(self, path_or_file: Union[str, io.TextIOBase]):
^
SyntaxError: invalid syntax

Warning - 'regex' module is not installed.

C:\Users\bnico\Desktop\redacted>python3 translateSfw.py gather
Warning - 'regex' module is not installed, JPEXSActionScriptParser heuristics will be less effective
Warning - cannot import one of 'stanza', 'jamdict', 'jaconv' modules - OfflineTranslator will not be available

I have executed the pip install regex command and it did not fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.