globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 602 forks source link

Any way to view/check loaded locales and their messages? #910

Open EngelPika32 opened 3 years ago

EngelPika32 commented 3 years ago

Hello,

although I don't think there is a way from what I have seen, I might be wrong.

This would be useful in two ways for me:

  1. I'd be able to check whether a message exists (at all and/or in a given language).
    • Fallback to the user's second language before/instead of the normal fallback to the root
    • Helpful for user-generated content that can be translated directly by others (Though, there are other ways for this.)
    • Iterating through a number of strings without knowing their number. ex.: Showing all possible values for an option. As I don't have to store the selected value, I have no point in using ids.
      {
      "root": {
      "possibleValues": {
      "egg": "egg",
      "cookie": "cookie",
      "pizza": "pizza"
      }
      }
      }
  2. Debugging and finding correct locales.
    • I sometimes struggle to know where which locale can be found. Looking into the live-objects would help a lot.
    • ex. At some point, strings were added under de-DE. Late then under de-CH. Now, some from de-CH aren't in de-DE and vice versa. de doesn't exist or is blank {} (which is okay, because it's never "asked"/needed). Afaik there is no 'good' way for them to fall back to each other (or having 'de' use both). And a "hack" isn't a preferable way. Therefore I'd like to track down such strings and merge them into each other (thus, having both locales a complete set of German strings).

Being able to inspect them while being in the debugger would be enough, I suppose.

(Note: I probably should check my writing tomorrow. I'm a bit tired from resolving all E_MISSING_MESSAGE_BUNDLE and E_MISSING_MESSAGE issues (gn8 for myself for now). Mostly caused by Issue 852 - open I dug as deep as I could and came across my wish (above^) from some weeks ago when I first implemented globalizejs.)

Almost forgot: Environment: nodejs (v13, v14, v15) globalize: v1.6.0 cldrjs: v0.5.5

// I'm loading:
globalize.load(
    require("cldr-data/supplemental/likelySubtags.json"),
    require("cldr-data/supplemental/plurals.json"),
    require("cldr-data/supplemental/ordinals.json")
);