Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Add Norwegian locale and corresponding test (failing as pr issue #146) #147

Merged
merged 8 commits into from
Oct 27, 2020

Conversation

Dambakk
Copy link

@Dambakk Dambakk commented Oct 19, 2020

See issue #146

@Dambakk
Copy link
Author

Dambakk commented Oct 19, 2020

This PR has expanded according to the findings described in #146

@soywiz
Copy link
Collaborator

soywiz commented Oct 20, 2020

First of all, thanks for the contribution @Dambakk !

I think we should have in mind several things:

This is changing the current behaviour. This is something we can consider for 2.0 as a breaking change, or opt-in/out with a setting or something.

We should ask people from different countries to validate the dates format and maybe also check against other libraries.
In Spanish for example I believe it is not capitalized between words, so could make sense. But in English I'm not fully sure since Title Case is usually common: https://dictionary.cambridge.org/grammar/british-grammar/dates
AFAIK in Japanese and Chinese no capitalization is required, but need to validate.

Going to ask on slack/discord, also if people subscribed to this repo can check, let's see if people from other countries have feedback on this for their respective languages, so lets wait a few days for this to happen if you don't mind 👍

@soywiz soywiz added this to KorGE 2.0 in Korlibs Oct 20, 2020
@@ -119,12 +137,12 @@ class KlockLocaleTest {
fun testRussianLocale() {
assertEquals(
"""
Ср, 13 Мар 2019 21:36:45 UTC
13 Мар 2019 г. 21:36:45
ср, 13 мар 2019 21:36:45 UTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The day of the week ("ср") should start with an upper letter ("Ср")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Can you confirm that all weekdays in two-letter short form should start with an upper case letter?

override val daysOfWeekShort = listOf(
		"вс", "пн", "вт", "ср", "чт", "пт", "сб"
	)

Can you type them here so it gets correct?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like that?

override val daysOfWeekShort = listOf(
    "Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
)

@Dambakk
Copy link
Author

Dambakk commented Oct 20, 2020

Of course this can wait, @soywiz!

I totally agree that this should be targeted for a major version. At least we are aware of the situation. I'm not a language person myself, but I hope the community will contribute with their knowledge. I can take responsibility to update this PR as we receive feedback.

Can you point me to any documentation that needs to be updated?

@tisoft
Copy link

tisoft commented Oct 20, 2020

German is looking good.

@joost-klitsie
Copy link

Dutch is looking good, officially the months/weekdays should not be capiticalized: https://onzetaal.nl/taaladvies/oktober-october/

@@ -173,12 +191,12 @@ class KlockLocaleTest {
fun testUkrainianLocale() {
assertEquals(
"""
Ср, 13 Бер 2019 21:36:45 UTC
13 Бер 2019 р. 21:36:45
ср, 13 бер 2019 21:36:45 UTC

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Ukrainian, the day of the week should start with an upper letter: "Ср" instead of "ср".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
Can you confirm that this is the correct two-letter short form for weekdays in Ukrainian?

override val daysOfWeekShort = listOf(
    "нд", "пн", "вт", "Ср", "чт", "пт", "сб"
)

Середа, 13 Березня 2019 р.
13 Березня 2019 р.
13 Бер 2019 р.
середа, 13 березня 2019 р.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full format of the day of the week should start with an upper letter as well.
"Середа" instead of "середа"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
Can you confirm that these weekdays are correct?

override val daysOfWeek = listOf(
    "неділя", "понеділок", "вівторок", "Середа", "четвер", "п'ятниця", "субота"
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cross-checking with how Java DateTime does formatting and gets an exception:

Expected :середа, 18 січня 1995 21:36:45 // <- Java
Actual   :Середа, 18 січня 1995 21:36:45 // <- Klock

Can you confirm that Java is wrong and that it should be uppercased?

@andriipanasiuk
Copy link

Left few comments for Ukrainian locale. Weekdays should be capitalized.

@soywiz
Copy link
Collaborator

soywiz commented Oct 22, 2020

Thank you all for the help!

Can you point me to any documentation that needs to be updated?

Klock documentation is on this file:

https://github.com/korlibs/korlibs.soywiz.com/blob/1ec80907cc805ced88a1bd495e8acf1d4473350c/klock/index.md


Also I have been thinking. Would be nice to be consisent with what Java and other libraries do in the case the behaviour is the same or very similar. What would you think on adding a test checking different locales on the jvmTest sourceSet that uses both klock and the JVM API to generate dates with weekdays and months and compare the results? That way we are completely confident to be consistent at least with the JVM.

moment().format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm"

I have also checked what does moment.js (not checked JVM), and seems to be different per language. Check the results here:

https://jsfiddle.net/soywiz/j35yht7a/6/

for (let lang of ['nb_NO', 'en', 'de', 'es', 'fr', 'zh-cn', 'ja-jp', 'pt_PT', 'nl-NL', 'ru']) {
	document.write('<p>' + lang + ": " + moment().locale(lang).format('dddd, MMMM Do YYYY, h:mm:ss a') + '</p>')
}
nb_NO: torsdag, oktober 22. 2020, 6:16:35 am
en: Thursday, October 22nd 2020, 6:16:35 am
de: Donnerstag, Oktober 22. 2020, 6:16:35 am
es: jueves, octubre 22º 2020, 6:16:35 am
fr: jeudi, octobre 22 2020, 6:16:35 am
zh-cn: 星期四, 十月 22日 2020, 6:16:35 早上
ja-jp: 木曜日, 10月 22日 2020, 6:16:35 午前
pt_PT: Quinta-feira, outubro 22º 2020, 6:16:35 am
nl-NL: donderdag, oktober 22ste 2020, 6:16:35 am
ru: четверг, октябрь 22-го 2020, 6:23:57 утра

We could also check this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat

That is the standard i18n for Ecmascript

@Dambakk
Copy link
Author

Dambakk commented Oct 22, 2020

That sounds like a great idea! I will look into it 👍

@Dambakk Dambakk requested a review from RezMike October 22, 2020 18:19
@Dambakk
Copy link
Author

Dambakk commented Oct 22, 2020

Strange, Portuguese is running fine on my computer. Both produce lowercased output.

@soywiz
Copy link
Collaborator

soywiz commented Oct 23, 2020

@Dambakk Nice. It's a pity that it didn't work consistently.
Korlibs libraries are compiled using JDK8 as far as I remember, to prevent bytecode issues, so maybe you are using a greater JVM version where the behaviour changed?
Can you try different versions of the JVM with your branch and see what happens?

If the behaviour is changed, maybe we should stick to specific literals, based on what's more common comparing with other libraries/frameworks like moment.js, the standardized version of ecmascript, several versions of the JVM, .NET, Swift.

If you need help with that I can make samples in different languages and put here the code + output when I have some time.

@Dambakk
Copy link
Author

Dambakk commented Oct 24, 2020

I was running java 12 so that might be it. IDEA crashed when I changed it to jdk 8 :P but since both the tests here and moment.js says something different than my computer I guess they are right ;)

However, Russian is failing now.. moment.js and my computer say weekdays should start with lowercase letter, whilst java 8(?) say weekdays should start with uppercased.. What do you think?

Anything else that you think should be done here? I can update the documentation once the PR is approved.

@soywiz
Copy link
Collaborator

soywiz commented Oct 25, 2020

Uhm. Tests are still failing. Maybe we should use string literals instead

@soywiz
Copy link
Collaborator

soywiz commented Oct 25, 2020

.NET:

using System;
using System.Globalization;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var date = new DateTime(2020, 10, 25, 14, 10, 13);
            var format = "dddd, dd MMMM yyyy hh:mm:ss tt";
            foreach (var lang in new[] {"nb_NO", "en", "de", "es", "fr", "zh-cn", "ja-jp", "pt_PT", "nl-NL", "ru"})
            {
                var str = date.ToString(format, CultureInfo.GetCultureInfo(lang));
                Console.WriteLine($"{lang}: {str}");
            }
        }
    }
}
nb_NO: søndag, 25 oktober 2020 02:10:13 p.m.
en: Sunday, 25 October 2020 02:10:13 PM
de: Sonntag, 25 Oktober 2020 02:10:13 PM
es: domingo, 25 octubre 2020 02:10:13 p. m.
fr: dimanche, 25 octobre 2020 02:10:13 PM
zh-cn: 星期日, 25 十月 2020 02:10:13 下午
ja-jp: 日曜日, 25 10月 2020 02:10:13 午後
pt_PT: domingo, 25 outubro 2020 02:10:13 PM
nl-NL: zondag, 25 oktober 2020 02:10:13 p.m.
ru: воскресенье, 25 октября 2020 02:10:13 PM

@soywiz
Copy link
Collaborator

soywiz commented Oct 25, 2020

In .NET looks similar to moment.js (english and german the only ones capitalized), except for Portuguese that is non-capitalized on .NET

@soywiz
Copy link
Collaborator

soywiz commented Oct 25, 2020

On standard modern JavaScript using Intl:

let date = new Date(Date.UTC(2020, 9, 25, 14, 10, 13));
let options = {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC', timeZoneName: 'short'};

for (let lang of ['nb-NO', 'en', 'de', 'es', 'fr', 'zh-cn', 'ja-jp', 'pt-PT', 'nl-NL', 'ru']) {
    try {
        let str = new Intl.DateTimeFormat(lang, options).format(date);
        console.log(`${lang}: ${str}`);
    } catch (e) {
        console.error(`Invalid locale ${lang}`);
    }
}
nb-NO: søndag 25. oktober 2020, UTC
en: Sunday, October 25, 2020, UTC
de: Sonntag, 25. Oktober 2020, UTC
es: domingo, 25 de octubre de 2020 UTC
fr: dimanche 25 octobre 2020 à UTC
zh-cn: 2020年10月25日星期日 UTC
ja-jp: 2020年10月25日日曜日 UTC
pt-PT: domingo, 25 de outubro de 2020, UTC
nl-NL: zondag 25 oktober 2020 UTC
ru: воскресенье, 25 октября 2020 г., UTC

Seems to work the same as on .NET, only English and German are capitalized

@soywiz
Copy link
Collaborator

soywiz commented Oct 25, 2020

Swift:

import Foundation

let date = Date.init()
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .long
for lang in ["nb-NO", "en", "de", "es", "fr", "zh-cn", "ja-jp", "pt-PT", "nl-NL", "ru"] {
    dateFormatter.locale = Locale.init(identifier: lang)
    print(dateFormatter.string(from: date))
}
25. oktober 2020 kl. 15:04:47 CET
October 25, 2020 at 3:04:47 PM GMT+1
25. Oktober 2020 um 15:04:47 MEZ
25 de octubre de 2020, 15:04:47 CET
25 octobre 2020 à 15:04:47 UTC+1
2020年10月25日 GMT+1 下午3:04:47
2020年10月25日 15:04:47 GMT+1
25 de outubro de 2020, 15:04:47 CET
25 oktober 2020 om 15:04:47 CET
25 октября 2020 г. в 15:04:47 GMT+1

Again, in terms of capitalization, only english and german. So I would go that way

@Dambakk
Copy link
Author

Dambakk commented Oct 27, 2020

Finally, the tests run successfully! Please go ahead with code review, @soywiz .

@Dambakk Dambakk requested a review from soywiz October 27, 2020 20:18
@soywiz
Copy link
Collaborator

soywiz commented Oct 27, 2020

LGTM Thanks!

@soywiz soywiz merged commit 7ecf095 into korlibs-archive:master Oct 27, 2020
Korlibs automation moved this from KorGE 2.0 to Done Oct 27, 2020
@soywiz
Copy link
Collaborator

soywiz commented Oct 27, 2020

Fixes #146

@Dambakk Dambakk deleted the feature/norwegian-locale branch October 27, 2020 20:27
@soywiz soywiz removed this from Done in Korlibs Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants