Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:19:54+00:00 2026-06-06T09:19:54+00:00

If i have a JSON with phrases in different languages: var lang = {

  • 0

If i have a JSON with phrases in different languages:

var lang = {
    'topic' : {
        'en' : 'Topic',
        'et' : 'Teema',
        'fi' : 'Aihe'
    },
    'MainPage' : {
        'en' : 'Main page',
        'et' : 'Pealeht',
        'fi' : 'Pääsivu'
    }//,
    //...etc
};

How to define a function for choosing a particular language:

function getText(lang, langKey) {
    //???????
    return langJson;
}

that outputs the same phrases like:

getText(lang, 'en'); //outputs {topic:'Topic',MainPage:'Main page',..}
getText(lang, 'et'); //outputs {topic:'Teema',MainPage:'Pealeht',..}
getText(lang, 'fi'); //outputs {topic:'Aihe',MainPage:'Pääsivu',..}

All the best: I

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:19:55+00:00Added an answer on June 6, 2026 at 9:19 am

    Basically you have to go through the whole lang object and pick the value for the correct language.

    Object.keys will return an Array containing the keys of your initial lang object.
    You can use those to create a new object.
    You could use a for loop to iterate over those keys and add the corresponding value to the resulting object, but I like to use reduce to do so:

    function getText(lang, langKey) {
      return Object.keys(lang).reduce(function(re, key) {
        re[key] = lang[key][langKey];
        return re;
      }, {})
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have json data being returned as a collection: var foo = [6, 7,
I have JSON/JS like this that populates data: var settingDefs = []; settingDefs.push({ name:'responses',
I have this JSON code: { phrases: [ { phrases: [ { id: 33,
I have JSON object inside variable like this: var chessPieces = { p-w-1 :
If I have JSON that is: var response = {results: 2938; id: 9283}; How
I have JSON string that has nested objects with dynamic names that vary each
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
I have Json returning as the following: [{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:39,ModifiedBy:,ModifiedDate:,Name:CF-39,StatusId:1,TrailCoordinates:[{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:1637,Latitude:32.76004207,Longitude:-97.34006853,ModifiedBy:,ModifiedDate:,SortOrder:1,TrailId:39},{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:1638,Latitude:32.76004333,Longitude:-97.34012121,ModifiedBy:,ModifiedDate:,SortOrder:2,TrailId:39}]},{CreatedBy:GIS_DB,CreatedDate:3/8/2012
I have JSON that keep changing , I need in android to keep updating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.