【问题标题】:Mobile application with multiple languages ​without using Google API具有多种语言的移动应用程序,无需使用 Google API
【发布时间】:2017-10-04 04:39:14
【问题描述】:

我想在 android 和 ios 应用程序中实现多种语言,但我不使用 google api,因为它是付费的

所以建议我用多种语言翻译整个应用程序数据或 php api 响应的最佳方法

【问题讨论】:

  • 您的问题不清楚,是否希望 UI 支持多种语言?
  • 是的,我的应用程序 UI 支持多种语言。我想要多语言的整个应用程序数据,例如。如果我在手机中选择中文,则整个应用程序数据以中文显示
  • 所以你希望服务器上的数据支持多种语言?
  • 是的,我希望服务器上的数据支持多种语言
  • 您似乎正在寻找服务来翻译服务器上的数据。这对于 StackOverflow 来说是题外话。来自stackoverflow.com/help/on-topicQuestions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

标签: php android ios


【解决方案1】:

首先您需要检查所有设备是否支持特定语言。

public static boolean isSupported(Context context, String text) {
        int w = 200, h = 80;

        Resources resources = context.getResources();
        float scale = resources.getDisplayMetrics().density;
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
        Bitmap orig = bitmap.copy(conf, false);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.rgb(0, 0, 0));
        paint.setTextSize((int) (14 * scale));

        // draw text to the Canvas center
        Rect bounds = new Rect();
        paint.getTextBounds(text, 0, text.length(), bounds);
        int x = (bitmap.getWidth() - bounds.width()) / 2;
        int y = (bitmap.getHeight() + bounds.height()) / 2;

        canvas.drawText(text, x, y, paint);
        boolean res = !orig.sameAs(bitmap);
        orig.recycle();
        bitmap.recycle();
        return res;
}

那么你就可以使用不同的资源xml文件了。

res->values->strings.xml

添加另一个values 文件夹另一种语言。就像如果你想添加古吉拉特语支持,你可以添加 values-gu 文件夹,并在 strings.xml 中添加与默认 strings.xml 相同的名称。

您的新 xml 文件将在此处

res->values-gu->strings.xml

您也可以查看详细信息。 Check here

现在对于 api 响应,保存选定的语言并通过 api 调用传递它并以特定语言返回结果。在数据库中,您必须以所有语言保存所有详细信息。检索数据时仅检索特定语言。

【讨论】:

  • 感谢您的回复。是的,我已经这样做了,但是对于翻译,我使用了谷歌翻译 api,它太贵了,所以我想要谷歌翻译 api 的替代方式
【解决方案2】:

使用 MS Azure API 可以免费使用很多次。我在我的一个动态翻译应用程序中使用它。

https://www.microsoft.com/en-us/translator/translatorapi.aspx

当您开始翻译这么多消息时会产生费用,但如果您拥有这么多用户,您可以负担得起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多