有什么方法可以将多种语言代码映射到一种语言代码,以便我可以在单个文件中进行翻译?

Is there any way to map many language codes to a single language code so that i can translate in a single file?

'en-*':'en_US',
'es-*':'es_ES', 
'pt-*':'pt_PT',
'fr-*':'fr_FR',
'de-*':'de_DE',
'ja-*':'ja_JP',
'it-*':'it_IT',
'*':'en_US'

有什么方法可以将 en-* 映射到 en_US 吗?我可能会得到任何浏览器语言环境,如 en-usen-au 等。因此我需要映射到此文件 en_US。如果有人知道请帮助。提前致谢。

正则表达式是你的朋友:)

var possible = [
  'en-us',
  'en-au',
  'fr-sb',
  'de-le',
  'it-nx'
]; // add to test

var locale = possible[Math.floor(Math.random() * possible.length)];

var routes = {
  'en-*':'en_US',
  'fr-*':'fr_FR',
  'de-*':'de_DE',
  '*':'en_US'
};

var match = (route) => new RegExp('^' + route.replace('*', '.*')).test(locale)
var route = Object.keys(routes).find(match);

console.log(locale, 'routed to', routes[route]);