Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve language tags #1354

Merged
merged 3 commits into from
Jan 3, 2023
Merged

preserve language tags #1354

merged 3 commits into from
Jan 3, 2023

Conversation

devsnek
Copy link
Contributor

@devsnek devsnek commented Dec 29, 2022

Fixes: #1335

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 29, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: devsnek / name: snek (3511882)

@devsnek devsnek marked this pull request as ready for review December 30, 2022 00:19
@diesieben07
Copy link
Collaborator

This is unfortunately not correct when the language tag contains a private use subtag (-x-). For example en-US-x-twain must turn into en-US-u-nu-hanidec-x-twain when combined with nu-hanidec. Your code would turn it into en-US-x-twain-u-nu-hanidec, which has a different meaning.

@@ -75,22 +75,26 @@ function parseLocaleString(localeStr) {
return [localeStr];
} else {
let options;
let selectedStr;
const smaller = localeStr.substring(0, uIndex);
Copy link
Member

Choose a reason for hiding this comment

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

You can now move this substring into the catch. It was only outside of it because we used it in the return.

@@ -695,7 +695,7 @@ test("DateTime.fromObject overrides the locale string with explicit settings", (
}
);

expect(res.locale).toBe("be");
expect(res.locale).toBe("be-u-ca-coptic-nu-mong");
expect(res.outputCalendar).toBe("islamic");
expect(res.numberingSystem).toBe("thai");
});
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a test here where you set the locale to something with a calendar and an explicit outputCalendar and show that it doesn't blow up (I don't care which calendar "wins", but the test should document the result, i.e. which calendar comes out of the resolved options)

Copy link
Contributor Author

@devsnek devsnek Dec 31, 2022

Choose a reason for hiding this comment

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

i think this is that test?

Copy link
Member

Choose a reason for hiding this comment

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

oh, ha, you're right. My bad

@devsnek
Copy link
Contributor Author

devsnek commented Dec 30, 2022

@diesieben07 do you have any suggestion for what should be done? Does this need to support private use subtags?

@diesieben07
Copy link
Collaborator

diesieben07 commented Dec 30, 2022

do you have any suggestion for what should be done?

You could either detect the -x- and insert the -u- at the appropriate position, but I think this would require more extensive changes of the code.
Alternatively you could strip out any -x- before appending (or throw an error), because I don't think the browser cares about any -x- tags. The problem with the current approach is that there won't be any error, the appended -u- will just be ignored by the browser.

Does this need to support private use subtags?

Probably not. But currently this code is a regression, because previously they were just ignored and now they cause the outputCalendar and numberingSystem to stop working.

Edit: I just want to clarify, that I am not a maintainer for this project, so I do not have any decision power here!

@icambron
Copy link
Member

icambron commented Jan 3, 2023

Looks good. Thanks!

@icambron icambron merged commit 806467a into moment:master Jan 3, 2023
@devsnek devsnek deleted the language-tags branch February 7, 2023 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BCP 47 language tags support
3 participants