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

Formatting option to render number before or in middle of label in weekLabel #7018

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hrkt
Copy link

@hrkt hrkt commented Nov 2, 2022

This PR is a proposal for weekLabel text formatting option for localization.

Motivation:

Current implementation of weekLabel can handle localization with a limiation of its label-and-number order.

i.e.
Week 1 (LTR)

Whereas in Japanese, week label is more suitable when it is rendered
number-and-label order, or label-number-label order.

i.e.
1週 (LTR)
第1週(LTR)

Google calendar renderes its weekLabel like above example.

Implementation idea:

This commit is a simple implementation that can parse weekLabel option with format string.

formatting rule:
- replace '{}' placeholder to week number

Given "第{}週" string in weekLabel option, it renders "第1週" text on weekLabel.

This code is tested with a limited unit test and rendering is confirmed by hand.

With its implementation, locale information file for Japanese language can be written like ja.ts.

This commit is a simple implementation that can parse weekLabel option with format string.

formatting rule:
- replace '{}' placeholder to week number

Given "第{}週" string in weekLabel option, it renders
"第1週" text on weekLabel.

This code is tested with a limited unit test and rendering is confirmed by hand.

With its implementation, locale information file for Japanese language can be written like ja.ts.
@hrkt
Copy link
Author

hrkt commented Nov 2, 2022

weekLabel with this proposal:
image

current weekLabel implementation:
image

c.f. Google calendar:
image

@acerix acerix changed the title proposal: add formatting feature to weekLabel Formatting option to render number before label in weekLabel Nov 7, 2022
@hrkt
Copy link
Author

hrkt commented Nov 8, 2022

Thank you for adding label, @acerix .

additional comment:

It might be specific for Japanese language, week number appears "in between" and "after" characters.
i.e.

"weekTextLong" option might be "第{number}週"
"weekText" option might be "{number}週"

Handling such case might be cumbersome, in such edge cases in i18n, it might be useful to give languages some degrees of formatting option.

In the scope of security consideration, if the i18n option will be given by programmers, replacing some characters will not cause a problem.
If this option might be given by external entities other than the site, we'll have to give some kind of sanitization logic here.

@acerix acerix changed the title Formatting option to render number before label in weekLabel Formatting option to render number before or in middle of label in weekLabel Nov 14, 2022
@hrkt
Copy link
Author

hrkt commented Nov 18, 2022

I also tried the displayed "week" label in other languages .

Chinese label in Google calendar
image

Koreanl in Google calendar
image

@hrkt
Copy link
Author

hrkt commented Dec 15, 2022

merged main branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants