简体   繁体   中英

How to provide i18n service for developer and end user

Many android applications have quite poor i18n-support, and for an understandable reason, as it adds much work for the developer.

From a both intuitive and cultural point of view it would be a good thing if end-users could translate the apps themself, and OTA share the translation, without reinstalling the app itself.

In concept; as wikipedia, some add content easily, others only use what's there.

It's of course important that the service is as easy as possible to use, both for app-developers, and people willing to transcribe.

To keep it simple, this is the solution I'm concidering;

Developer perspective:

  • Developer uses a customized setContentView when open activities/layouts that will seach for thanslations of xml-entries. (below)

  • The customized version is provided as a free downloadable library/class..., turning the i18n feature to more or less a one liner.

User perspective:

  • User downloads app without any translation

  • As app launches, it checks locale running at phone, and will look for a translated xml-file at shared space in SD.

  • If no or old transcribed xml (above), try to download new from internet-service (ansync). This is all done by library above, no need for intents.

Translator perspective:

  • Separate app to provide translations for any app using the i18n service above. (Could be just a webapp), with some form of QA on translators/input.

QUESTION: Now, for this to work efficiently, it has to be AeasyAP for the developer to even bother, and the most fluent solution would be a customized version of setContentView, that simply loads the translated values from external xml, instead of the ones in the apk.

Is this possible at all, and if not, what's your suggested solutions?

(And of course, Happy New Year, feliz ano novo, blwyddyn newydd dda, Gott Nytt År, kontan ane nouvo, szczęśliwego nowego roku ... )

Regards, /T

Yes, it's possible only if someone (probably you or me or others) will rewrite setContentView() - since I see root of a problem only there. Let me explain:

  1. Layout XML's are stored in res/layout which packaged in APK
  2. There's no way to modify APK runtime (at least I've never heard about it)
  3. That means basically you can't redefine on-line/runtime customized/internationalized layout XML's in res/layout
  4. So you'd need a place where to store customized XML's: either in preferences or in SQLite
  5. In both cases one'd need to inflate XML in Activity/Dialog, which can be done through setContentView
  6. So in the end - you have to redefine setContentView

How to do that? 2 options:

  • Heroic: completely rewrite setContentView in Android sources
  • Less heroic: create your own OwnActivity class which will redefine setContentView(int id) . For instance: OwnActivity.setContentView() looks inside SQLite for known XML id with current locale, if not found it inflates XML from res/layout

EDIT1:

You can override it like:

public class MyActivity extends Activity
{
    @Override
    public void setContentView(int id)
    {
        if(checkPresenceInStorage(id))
            //...
        else
            super.setContentView(id);
    }
}

Regarding the second part of the question, it is possible to use an existing translation service like Launchpad , which operates on .po files for gettext. There is however android2po, which can transform between Android's XML and the gettext .po format.

There are already some Android translations on Launchpad, eg ConnectBot, however the service requires a login to be able to contribute. Alternatively, you should look at the available gettext-based web translator suites you can run yourself as well, like Pootle.

Sorry, I am not allowed to post more than one URL. Please google the rest up :(

layoutinflator.factory是我一直在寻找的...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM