mozilla-mobile / mozilla-vpn-client

A fast, secure and easy to use VPN. Built by the makers of Firefox.
https://vpn.mozilla.org
Other
477 stars 116 forks source link

[zh-TW] Time string rendered into a wired "B"time #9902

Open petercpg opened 1 month ago

petercpg commented 1 month ago

Describe the bug When the VPN App is in zh-TW locale, times in UI are prefixed with a "B" character.

VPN version:

Affected Platforms:

Prerequisites: N/A

Steps to reproduce:

  1. Install VPN app
  2. Switch to zh-TW locale
  3. Observe time string on the Home or Message page

Expected result:

  1. The absolute time should be a time.

Actual result:

  1. The absolute time is prefixed with a B character, eg., Last Updated: B22:35.
  2. For relative times, e.g, "Yesterday" there is no redundant character.

Additional notes: 圖片 圖片 圖片

The string in localization do not have redundant character either. https://github.com/mozilla-l10n/mozilla-vpn-client-l10n/blob/8bd871f5604ffcf26f89c60be1b66da7a650b5d7/zh_TW/mozillavpn.xliff#L1924

ValentinaPC commented 1 month ago

Hello @petercpg ! Thank you for logging this. This was also tracked in the past, here - https://mozilla-hub.atlassian.net/browse/VPN-4488 . We should decide on the validity of this issue. CC: @albionx @flodolo

flodolo commented 1 month ago

FYI, Peter is part of our community of volunteers and doesn't have access to internal Jira tickets. Clearly this is a valid issue, probably coming out of qt libraries.

flodolo commented 1 month ago

@petercpg I forgot that this was originally reported for zh-CN (zh_Hans) and I did investigate, but I missed an important part.

Time for zh_Hant is set as Bh:mm in CLDR (link), across the board. But that B needs to be localized as well, while here it stays as B.

Examples from Firefox console

const today = new Date(Date.UTC(2024, 09, 25, 11, 51, 0, 0)); 
console.log(new Intl.DateTimeFormat('zh-TW', { timeStyle: 'short' }).format(today)); 
> 上午11:51

console.log(new Intl.DateTimeFormat('zh-Hant', { timeStyle: 'short' }).format(today)); 
> 上午11:51

https://cldr.unicode.org/translation/date-time/date-time-patterns#basic-time-formats

B to use day periods like “in the afternoon” instead of AM/PM.

That seems indeed like a bug in qt, or in the library they use to access CLDR-based functions.

petercpg commented 1 month ago

Is it possible to expose date format strings to l10n, so localizers can override them, or for zh-TW, use HH:mm forcibly as a workaround, until Qt fixes the problem?

flodolo commented 1 month ago

I would really prefer to avoid exposing strings for date/time formatting.

flodolo commented 1 month ago

At least Qt 6.7.2 seems to work correctly, so maybe the issue is in the VPN code

#include <QCoreApplication>
#include <QLocale>
#include <QTime>
#include <QDateTime>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QTime currentTime = QTime::currentTime();

    QLocale locale_en_US(QLocale("en-US"));
    QLocale locale_zh_Hant(QLocale("zh-Hant"));
    QLocale locale_zh_TW(QLocale("zh-TW"));

    // Format time in different locales
    QString time_en_US = locale_en_US.toString(currentTime, QLocale::ShortFormat);
    QString time_zh_Hant = locale_zh_Hant.toString(currentTime, QLocale::ShortFormat);
    QString time_zh_TW = locale_zh_TW.toString(currentTime, QLocale::ShortFormat);

    // Output the formatted times
    qDebug() << "Time for en-US (short format):" << time_en_US;
    qDebug() << "Time for zh-Hant (short format):" << time_zh_Hant;
    qDebug() << "Time for zh-TW:" << time_zh_TW;

    return a.exec();
}

Time for en-US (short format): "10:49 AM" Time for zh-Hant (short format): "上午10:49" Time for zh-TW: "上午10:49"