如何为开发者和最终用户提供国际化服务

发布于 2024-10-09 16:53:04 字数 1059 浏览 7 评论 0原文

许多 Android 应用程序的 i18n 支持都很差,这是一个可以理解的原因,因为它为开发人员增加了很多工作。

从直观和文化的角度来看,如果最终用户可以自己翻译应用程序,并且 OTA 共享翻译,而无需重新安装应用程序本身,那将是一件好事。

在概念上;就像维基百科一样,有些可以轻松添加内容,有些则只使用现有内容。

当然,对于应用程序开发人员和愿意转录的人来说,该服务尽可能易于使用非常重要。

为了简单起见,这是我正在考虑的解决方案;

开发人员视角:

  • 开发人员在打开活动/布局时使用自定义的 setContentView 来搜索 xml 条目的翻译。 (如下)

  • 定制版本作为免费下载的库/类提供...,将 i18n 功能或多或少地变成一个行。

用户视角:

  • 用户下载不带任何翻译的应用

  • 应用启动时,它会检查手机上运行的区域设置,并查找翻译后的 xml -SD 共享空间中的文件。

  • 如果没有或旧的转录 xml(上面),请尝试从互联网服务下载新的(异步)。这都是由上面的库完成的,不需要意图。

翻译者视角

  • 单独的应用程序可为使用上述 i18n 服务的任何应用程序提供翻译。 (可能只是一个网络应用程序),对翻译器/输入进行某种形式的质量检查。

问题: 现在,为了使其高效工作,开发人员必须使用 AeasyAP,而最流畅的解决方案是 setContentView 的自定义版本,它只需从外部 xml 加载翻译后的值,而不是 apk 中的值。

这是否可能,如果不可能,您建议的解决方案是什么?

(当然,新年快乐,feliz ano novo,blwyddyn newydd dda,Gott Nytt År,kontan ane nouvo,szczęśliwego nowego roku ...

问候, /T

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

趁微风不噪 2024-10-16 16:53:04

是的,只有当有人(可能是你或我或其他人)重写 setContentView() 时才有可能 - 因为我只在那里看到问题的根源。让我解释一下:

  1. 布局 XML 存储在打包在 APK 中的 res/layout 中
  2. 无法修改 APK 运行时(至少我从未听说过)
  3. 这意味着基本上你无法重新定义在线/运行时定制/国际化res/layout 中的布局 XML
  4. 因此,您需要一个存储自定义 XML 的位置:无论是在首选项中还是在 SQLite 中,
  5. 在这两种情况下,都需要在 Activity/Dialog 中膨胀 XML,这可以通过 setContentView 来完成/code>
  6. 所以最后 - 你必须重新定义 setContentView

如何做到这一点? 2 个选项:

  • 英雄: 在 Android 源代码中完全重写 setContentView
  • 不那么英雄: 创建您自己的 OwnActivity 类,该类将重新定义 setContentView(int id )。例如: OwnActivity.setContentView() 在 SQLite 内部查找具有当前语言环境的已知 XML id,如果没有找到,它会从 res/layout 中扩充 XML

EDIT1:

您可以像这样覆盖它:

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

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);
    }
}
带上头具痛哭 2024-10-16 16:53:04

关于问题的第二部分,可以使用现有的翻译服务,例如 Launchpad,它在 < gettext 的 em>.po 文件。
不过,还有 android2po,它可以在 Android 的 XML 和 gettext .po 格式之间进行转换。

Launchpad 上已经有一些 Android 翻译,例如 ConnectBot,但是该服务需要登录才能贡献。或者,您应该查看可用的基于 gettext 的网络翻译套件,您也可以自己运行,例如 Pootle。

抱歉,我不允许发布多个 URL。请用谷歌搜索其余部分:(

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, e.g. 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 :(

四叶草在未来唯美盛开 2024-10-16 16:53:04

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

layoutinflator.factory is what I was looking for...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文