第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

能夠?qū)⒁粋€(gè)或多個(gè)詞從一種語(yǔ)言映射到另一種語(yǔ)言的可靠國(guó)際化方法是什么樣子的?

能夠?qū)⒁粋€(gè)或多個(gè)詞從一種語(yǔ)言映射到另一種語(yǔ)言的可靠國(guó)際化方法是什么樣子的?

DIEA 2023-06-09 15:27:26
我有一系列工作日 [“星期一”,“星期二”..等],我需要將每一天翻譯成另一種語(yǔ)言。let weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; translatedArray = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi'];最好的方法是什么?我需要輸出一個(gè)帶有翻譯數(shù)組的新數(shù)組
查看完整描述

5 回答

?
冉冉說(shuō)

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊

您可以使用Array reduce方法來(lái)制作結(jié)果對(duì)象。


let weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];


let translatedArray = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi"];


let ret = weekdays.reduce((p, c, i) => {

  p[c] = translatedArray[i];

  return p;

}, {});

console.log(ret);

console.log(ret["Tuesday"]); 


查看完整回答
反對(duì) 回復(fù) 2023-06-09
?
開(kāi)滿(mǎn)天機(jī)

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊

我的簡(jiǎn)單方法是在這樣的對(duì)象中維護(hù)一個(gè) json


let weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];

let anotherLanguageDays = {

   "Monday" : "星期一",

    "Tuesday" : "星期一",

    ... and so on

};

現(xiàn)在當(dāng)你遍歷數(shù)組時(shí)你可以做這樣的事情


weekdays.forEach(d => {

   console.log(anotherLanguageDays[d]);

})

您的代碼的完整示例...


let weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];



let anotherLangauge = {

  Monday : "Lundi",

  Tuesday : "Mardi",

  Wednesday : "Mercredi",

  Thursday : "Jeudi",

  Friday : "Vendredi"

};



weekdays.forEach(d => {

  console.log(anotherLangauge[d]);

})


查看完整回答
反對(duì) 回復(fù) 2023-06-09
?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊

使用代表語(yǔ)言代碼的鍵創(chuàng)建一個(gè)對(duì)象。每種語(yǔ)言代碼都有另一個(gè)對(duì)象,其中包含單詞和該語(yǔ)言中單詞的翻譯。


編寫(xiě)一個(gè)函數(shù),該函數(shù)接受一個(gè)字符串?dāng)?shù)組作為您要翻譯的單詞,以及一個(gè)指示從哪種語(yǔ)言獲取翻譯的語(yǔ)言代碼。


確保將所有鍵都小寫(xiě)以保持統(tǒng)一。這些值沒(méi)有小寫(xiě)。


按照這種方法,您可以通過(guò)添加更多語(yǔ)言和單詞來(lái)輕松擴(kuò)展。


const translations = {

  'en-US': {

    monday: 'Monday',

    tuesday: 'Tuesday',

    wednesday: 'Wednesday', 

    thursday: 'Thursday', 

    friday: 'Friday',

    saturday: 'Saturday',

    sunday: 'Sunday'

  },

  'fr-FR': {

    monday: 'Lundi',

    tuesday: 'Mardi',

    wednesday: 'Mecredi', 

    thursday: 'Jeudi', 

    friday: 'Vendredi',

    saturday: 'Samedi',

    sunday: 'Dimanche'

  },

  'nl-NL': {

    monday: 'Maandag',

    tuesday: 'Dinsdag',

    wednesday: 'Woensdag', 

    thursday: 'Donderdag', 

    friday: 'Vrijdag',

    saturday: 'Zaterdag',

    sunday: 'Zondag'

  }

};


const translate = (strings, language) => {

  if (!translations.hasOwnProperty(language)) {

    throw new Error(`Language ${language} does not exist in the translations object.`);

  }

  const set = translations[language];

  return Object.entries(set)

    .filter(([ key, value ]) => strings.includes(key))

    .map(([ key, value ]) => value);

};


let weekdays = [

  'monday', 

  'tuesday', 

  'wednesday', 

  'thursday', 

  'friday'

];


const frenchWeekdays = translate(weekdays, 'fr-FR');

const englishWeekdays = translate(weekdays, 'en-US');

const dutchWeekdays = translate(weekdays, 'nl-NL');


console.log(frenchWeekdays);

console.log(englishWeekdays);

console.log(dutchWeekdays);


// Example with non existent translations.

translate(weekdays, 'de-DE');


查看完整回答
反對(duì) 回復(fù) 2023-06-09
?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

它主要?dú)w結(jié)為選擇最方便的mapping 方法。一種可能的方法可能類(lèi)似于下一個(gè)提供的示例代碼......

const i18nMap = {

? "en-GB": {

? ? weekdays: {

? ? ? monday: "Monday",

? ? ? tuesday: "Tuesday",

? ? ? wednesday: "Wednesday",

? ? ? thursday: "Thursday",

? ? ? friday: "Friday",

? ? },

? },

? "fr-FR": {

? ? weekdays: {

? ? ? monday: "Lundi",

? ? ? tuesday: "Mardi",

? ? ? wednesday: "Mercredi",

? ? ? thursday: "Jeudi",

? ? ? friday: "Vendredi",

? ? },

? },

? "de-DE": {

? ? weekdays: {

? ? ? monday: "Montag",

? ? ? tuesday: "Dienstag",

? ? ? wednesday: "Mittwoch",

? ? ? thursday: "Donnerstag",

? ? ? friday: "Freitag",

? ? },

? },

};


function getItemFromBoundLanguageMap(item) {

? return this[item];

}


// let weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];

const weekdaysKeyList = Object.keys(i18nMap["en-GB"].weekdays);


const weekdaysEnGB = weekdaysKeyList.map(

? getItemFromBoundLanguageMap,

? i18nMap["en-GB"].weekdays

);

const weekdaysFrFR = weekdaysKeyList.map(

? getItemFromBoundLanguageMap,

? i18nMap["fr-FR"].weekdays

);

const weekdaysDeDE = weekdaysKeyList.map(

? getItemFromBoundLanguageMap,

? i18nMap["de-DE"].weekdays

);


console.log("weekdaysKeyList :", weekdaysKeyList);


console.log("weekdaysEnGB :", weekdaysEnGB);

console.log("weekdaysFrFR :", weekdaysFrFR);

console.log("weekdaysDeDE :", weekdaysDeDE);

.as-console-wrapper { min-height: 100%!important; top: 0; }



查看完整回答
反對(duì) 回復(fù) 2023-06-09
?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以執(zhí)行以下操作:


let arr = ["Mon", "Tue"]

let mapping = {

  "Mon":"aaa",

  "Tue":"sss"

}

newArr = arr.map((str) => {

  return mapping[str];

});

console.log(newArr) //["aaa","sss"]


查看完整回答
反對(duì) 回復(fù) 2023-06-09
  • 5 回答
  • 0 關(guān)注
  • 382 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)