Git Product home page Git Product logo

apkeditor_plugin_translation's Introduction

apkeditor_plugin_translation

A sample translation plugin for APK Editor (Pro). In this project, src directory contains source code of the sample translation plugin; translate_debugger.zip is a patch to correct some spoiled variables (like "1 $%") which are wrongly translated by the translation plugin. (The patch is provided by a Russian friend)

It only makes sense when APK Editor (Pro) is installed:

APK Editor: https://play.google.com/store/apps/details?id=com.gmail.heagoo.apkeditor

APK Editor Pro: https://play.google.com/store/apps/details?id=com.gmail.heagoo.apkeditor.pro

Please uncomment following lines in AndroidManifest.xml if built for free version:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="application/com.gmail.heagoo.apkeditor-translate" />
    </intent-filter>

To develop a translation plugin, you should create your own activity, which can get translation request and return the translation result. The translation request is sent in terms of TranslateItem which is defined as:

package com.gmail.heagoo.apkeditor.translate;
 
import java.io.Serializable;

public class TranslateItem implements Serializable {
 
    private static final long serialVersionUID = -3101805950698159689L;
    public String name;
    public String originValue;
    public String translatedValue;
 
    public TranslateItem(String _n, String _o) {
       this.name = _n;
       this.originValue = _o;
    }
 
    public TranslateItem(String _n, String _o, String _t) {
       this.name = _n;
       this.originValue = _o;
       this.translatedValue = _t;
    }
}

And, please refer to following code to get all the passed parameters:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // ...
       Intent intent = getIntent();
       Bundle bundle = intent.getExtras();
       // Target language code like "-de"
       this.targetLanguageCode = bundle.getString("targetLanguageCode");
       // Translated items are also passed, so that we can revise it
       this.translatedFilePath = bundle.getString("translatedList_file");
       this.translatedList = (List<TranslateItem>) readObjectFromFile(translatedFilePath);
       // Untranslated items, which are to be translated
       String path =bundle.getString("untranslatedList_file");
       this.untranslatedList = (List<TranslateItem>) readObjectFromFile(path);
       // ...
    }
 
    public static Object readObjectFromFile(String filePath) {
       Object result = null;
       File file = new File(filePath);
       ObjectInputStream objIn = null;
       try {
           objIn = new ObjectInputStream(new FileInputStream(file));
           result = objIn.readObject();
       } catch (IOException e) {
           e.printStackTrace();
       } catch (ClassNotFoundException e) {
           e.printStackTrace();
       } finally {
           closeWithoutThrow(objIn);
       }
       return result;
    }

After the translation, we should return back the result using following code:

    private void setResult(List<TranslateItem> stringValues) {
       Intent intent = new Intent();
       intent.putExtra("targetLanguageCode", this.targetLanguageCode);
       writeObjectToFile(this.translatedFilePath, stringValues);
       intent.putExtra("translatedList_file", this.translatedFilePath);
 
       this.setResult(RESULT_OK, intent);
    }
 
    public static void writeObjectToFile(String filePath, Object obj) {
       File file = new File(filePath);
       ObjectOutputStream objOut = null;
       try {
           objOut = new ObjectOutputStream(new FileOutputStream(file));
           objOut.writeObject(obj);
           objOut.flush();
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           closeWithoutThrow(objOut);
       }
    }

As there may be thousands of TranslateItem, thus it is passed by file, not by itself.

apkeditor_plugin_translation's People

Contributors

heagoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apkeditor_plugin_translation's Issues

Not save.

After completing the translation process, clicking Save only returns the string without any changes (translation)

ApkEditor Pro 1.8.8

Build

Who can build it?

Download the app

How to download the app The links in Google Play do not work?

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.