Skip to content

Instantly share code, notes, and snippets.

@DerGoogler
Created February 26, 2022 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DerGoogler/4a24d06142c1a60d5df2b401689ee939 to your computer and use it in GitHub Desktop.
Save DerGoogler/4a24d06142c1a60d5df2b401689ee939 to your computer and use it in GitHub Desktop.
Translation with JavaScript
// Declare language
const lang = "en";
// Set global string
const globals = {
en: {
sampleText1: "This is an Sample 1",
sampleText2: "This is an Sample 2",
},
de: {
sampleText1: "Dies ist ein Sample 1",
sampleText2: "Dies ist ein Sample 2",
},
};
// Get strings
const string = globals[lang];
/**
* @retuens This is an Sample 1
*/
console.log(string.sampleText1);
/**
* @returns This is an Sample 2
*/
console.log(string.sampleText2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment