question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there any way to return an entire namespace via the translate function?

See original GitHub issue

I have a datepicker component, which takes an object for localisation:

{
  "lang": {
    "placeholder": "Select date",
    "rangePlaceholder": [
      "Start date",
      "End date"
    ],
    "today": "Today",
    "now": "Now",
    "backToToday": "Back to today",
    "ok": "Ok",
    "clear": "Clear",
    "month": "Month",
    "year": "Year",
    "timeSelect": "Select time",
    "dateSelect": "Select date",
    "monthSelect": "Choose a month",
    "yearSelect": "Choose a year",
    "decadeSelect": "Choose a decade",
    "yearFormat": "YYYY",
    "dateFormat": "M/D/YYYY",
    "dayFormat": "D",
    "dateTimeFormat": "M/D/YYYY HH:mm:ss",
    "monthFormat": "MMMM",
    "monthBeforeYear": true,
    "previousMonth": "Previous month (PageUp)",
    "nextMonth": "Next month (PageDown)",
    "previousYear": "Last year (Control + left)",
    "nextYear": "Next year (Control + right)",
    "previousDecade": "Last decade",
    "nextDecade": "Next decade",
    "previousCentury": "Last century",
    "nextCentury": "Next century"
  },
  "timePickerLocale": {
    "placeholder": "Select time"
  }
}

I have this in my translations as datepicker, however accessing t('datepicker') returns undefined, presumably because it’s meant to return a string, not an object.

I can access what I need via: i18n.getResourceBundle(i18n.languages[0]).datepicker, but I’m wondering if there is any way to do the same via the translate function itself, as this solution feels a bit hacky.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
urtheonecommented, Nov 17, 2020

I solved it this way : i18next.store.getResourceBundle(language, namespace);

1reaction
onionhammercommented, Nov 7, 2019

@jamuhl that’s a key, not the namespace

Read more comments on GitHub >

github_iconTop Results From Across the Web

Essentials - i18next documentation
Namespaces are a feature in i18next internationalization framework which allows you to separate translations that get loaded into multiple files. init.
Read more >
Namespaces - cppreference.com
The unique name is unique over the entire program, but within a translation unit each unnamed namespace definition maps to the same unique ......
Read more >
XQuery, XPath, and XSLT Functions and Operators ... - W3C
Retrieves a document using a URI supplied as an xs:string , and returns the corresponding document node. doc-available. doc-available(xs:string ...
Read more >
Namespaces (C++) - Microsoft Learn
Use a using directive in an implementation file (i.e. *.cpp) if you are using several different identifiers in a namespace; if you are...
Read more >
URL dispatcher - Django documentation
Django also provides a way to translate URLs according to the active language. ... Returns a UUID instance. path - Matches any non-empty...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found