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.

Load namespaces with variable from another file

See original GitHub issue

Hi, I want to load namespaces with variable from another file. I try this;

import { ABOUT_US } from "./src/core/routes";

module.exports = {
	locales: ["az", "ru"],
	defaultLocale: "az",
	pages: {
		"*": ["common", "metatags", "menus", "slip", "components", "forms", "validationMessages", "cookiePolicy", "personalDataProtection", "termsOfUse", "personalDataApplication", "responsibleBetting", "ourLogos", "advertisingFilms", "sponsors", "member"],
		ABOUT_US: ["aboutUs"],
	},
	loadLocaleFrom: (lang, ns) =>
		import(`./src/locales/${lang}/${ns}.json`).then((m) => m.default),
};

But it does not work. How can i do this? Please help me!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ErkanKabilcommented, Oct 22, 2021

Thank you, its worked!

1reaction
aralrocacommented, Oct 22, 2021

Replace the first line to

const {
	ABOUT_US,
	ADVERTISING_FILMS,
	COOKIES_POLICY,
	OUR_LOGOS, PERSONAL_DATA_APPLICATION,
	PERSONAL_DATA_PROTECTION,
	RESPONSIBLE_BETTING,
	SPONSORS,
	TERMS_OF_USE,
} = require("./src/core/routes");

And your other file should be:

module.exports = {
  COOKIES_POLICY: "/cookie-siyaseti",
  ABOUT_US  "/haqqimizda",
  PERSONAL_DATA_PROTECTION: "/sexsi-melumatlarin-qorunmasi",
  // ...rest
}

The dynamic import inside loadLocaleFrom is not a problem. https://github.com/vinissimus/next-translate/blob/master/examples/complex/i18n.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use variable from resource another .cs file with "using"
OK, I want to have a file that contains something like A = 1 B = 2 C = 3 and then I...
Read more >
c++ - Load values from txt to variables in namespace
Is it possible to load the txt file and define the variables inside the namespace or I have to rewrite everything that is...
Read more >
Namespaces — Mako 1.2.4 Documentation
Namespaces are used to organize groups of defs into categories, and also to “import” defs from other files. ... The comp variable above...
Read more >
R Packages (2e) - 11 Dependencies: Mindset and Background
Each namespace has an imports environment that can contain bindings to functions used by the package that are defined in another package. The...
Read more >
6. Modules — Python 3.11.1 documentation
Each module has its own private namespace, which is used as the global namespace by all functions defined in the module. Thus, the...
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