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

Localization broken in field-date #1530

Closed
frck006 opened this issue Jan 26, 2023 · 4 comments
Closed

Localization broken in field-date #1530

frck006 opened this issue Jan 26, 2023 · 4 comments
Labels
type: bug Something isn't working

Comments

@frck006
Copy link

frck006 commented Jan 26, 2023

It's more a question than a bug.
I would like to know how to change the local in @blockly/field-date ?

When I set 'fr', this change "today" but not the month.
image

Thanks

@frck006 frck006 added triage type: bug Something isn't working labels Jan 26, 2023
@frck006 frck006 changed the title How to change the local about @blockly/field-date How to change the local about @blockly/field-date ? Jan 26, 2023
@cpcallen cpcallen added type: question Further information is requested and removed type: question Further information is requested labels Jan 30, 2023
@cpcallen cpcallen changed the title How to change the local about @blockly/field-date ? Localization broken in field-date Jan 30, 2023
@cpcallen cpcallen removed the triage label Jan 30, 2023
@cpcallen
Copy link
Contributor

cpcallen commented Jan 30, 2023

I am pretty sure this is actually a bug.

You don't describe how your code changes the locale, but I added

import * as Fr from 'blockly/msg/fr';
Blockly.setLocale(Fr);

to the top of plugins/field-date/test/index.js (just beneath import * as Blockly…), and was able to reproduce exactly.

I believe the problem is in FieldDate.loadLanguage_:

  static loadLanguage_() {
    for (const prop in goog.i18n) {
      if (prop.startsWith('DateTimeSymbols_')) {
        const lang = prop.substr(16).toLowerCase().replace('_', '.');
        // E.g. 'DateTimeSymbols_pt_BR' -> 'pt.br'
        if (goog.getObjectByName(lang, Blockly.Msg)) {
          goog.i18n.DateTimeSymbols = goog.i18n[prop];
          break;
        }
      }
    }
  }

As far as I can tell this is expecting to find a property named Blockly.Msg.fr(or whatever language has been set) and no such property exists so goog.i18n.DateTimeSymbols is never set.

I'm not really sure how this could ever have worked. Did Blockly.Msg formerly have a property named for the language loaded?

@alicialics
Copy link
Contributor

Looks like the snippet above (ie loadLanguage_() was removed in #1705
Instead of goog.ui.DatePicker() it was replaced with browser's native date picker. However it does mean that the strings won't be localized if the browser locale != Blockly locale.

cc @BeksOmega

@rachel-fenichel
Copy link
Collaborator

Is there a way to force the native date picker to use a specific locale by code other than the browser locale?

@rachel-fenichel
Copy link
Collaborator

It looks like we don't have a way to force the locale of the date picker. However, if there's a mismatch between Blockly locale and browser locale there's a good chance that the browser locale is the user's actual preferred locale, and that they will understand the month strings that are available. This seems acceptable, given that it allows us to not implement a custom date picker (or import one from elsewhere, as we did with the Closure UI library).

@rachel-fenichel rachel-fenichel closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
@cpcallen cpcallen removed the triage label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants