Angular i18n国际标准化组织国家/地区7个显示国家/地区,具体取决于当前语言

Angular i18n国际标准化组织国家/地区7个显示国家/地区,具体取决于当前语言,angular,angular-i18n,Angular,Angular I18n,对我来说,i18n iso国家的文档有点混乱。我有一个Angular 7项目,只想根据用户当前的语言在注册表中向用户显示所有国家/地区 所以我知道,i18nIsoCountries.getNames(“en”)会获取所有名称和一种JSON输出。使用this.translateService.currentLang我可以轻松获得当前语言,但目前我有一个静态的、自己编写的JSON文件,仅用于英语语言,并以我的形式显示它们 我还想过滤我可以写Ger的国家,并得到德国的建议。它现在已经实现并且可以工作,

对我来说,i18n iso国家的文档有点混乱。我有一个Angular 7项目,只想根据用户当前的语言在注册表中向用户显示所有国家/地区

所以我知道,
i18nIsoCountries.getNames(“en”)
会获取所有名称和一种JSON输出。使用
this.translateService.currentLang
我可以轻松获得当前语言,但目前我有一个静态的、自己编写的JSON文件,仅用于英语语言,并以我的形式显示它们

我还想过滤我可以写Ger的国家,并得到德国的建议。它现在已经实现并且可以工作,但是我不知道如何使用库来实现它

注册组件:

import country from'../../assets/countriesJson.json';
出口接口国{
名称:字符串;
代码:字符串;
}
导出类注册组件实现OnInit{
@ViewChild(“步进器”)步进器:MatStepper;
过滤国家:可见;
countryList:Country[]=Country.countries;
恩戈尼尼特(){
this.filteredCountries=this.personalForm.controls['country'].valueChanges
.烟斗(
startWith(“”),
映射(值=>this.\u过滤器国家(值))
);
}
private _filterCountries(值:字符串):国家[]{
常量filterValue=value.toLowerCase();
返回这个.countryList.filter(country=>country.name.toLowerCase().indexOf(filterValue)==0);
//const filterValue=value.toLowerCase();变量für Suche bei dem Begriff nur enthalten ist Ger->阿尔及利亚
//返回这个.countryList.filter(option=>option.name.toLowerCase().includes(filterValue));
}
CountriesJson(缩写):

html:


{{country.name}
{{'REGISTRATION.COUNTRY'| translate}}{{'VALIDATION.REQUIRED'| translate}}
因此,我脑海中的想法是以某种方式将这些国家暂时保存为某种类型的数据,使用
i18niscocountries.getNames(“en”)
我解决了这个问题:

countries=[]作为数组
过滤国家:可见;
恩戈尼尼特(){
this.startDate.setFullYear(this.startDate.getFullYear()-18);
这个.buildForm();
this.filteredCountries=this.personalForm.controls['country'].valueChanges
.烟斗(
startWith(“”),
映射(值=>this.\u过滤器(值))
);
i18niscocountries.registerLocale(require(“i18n iso-countries/langs/en.json”);
i18niscocountries.registerLocale(require(“i18n iso countries/langs/de.json”);
this.currentLanguage=this.translateService.currentLang;
indexedArray=i18nIsoCountries.getNames(this.currentLanguage);
for(输入indexedArray){
让值=indexedArray[键];
这个。国家。推动(价值);
}
}
private_过滤器(值:string):string[]{
var滤波值;
如果(值){
filterValue=value.toLowerCase();
}否则{
filterValue=“”;
}
返回此.countries.filter(option=>option.toLowerCase().startsWith(filterValue));
}
ngAfterContentChecked(){
this.cdRef.detectChanges();
if(this.currentLanguage!=this.translateService.currentLang){
indexedArray=i18nIsoCountries.getNames(this.translateService.currentLang);
这个国家=[];
for(输入indexedArray){
让值=indexedArray[键];
这个。国家。推动(价值);
}
this.currentLanguage=this.translateService.currentLang;
this.personalForm.get('country').updateValueAndValidity();
}
}
以及html部分:


{{option}}
{{'REGISTRATION.COUNTRY'| translate}}{{'VALIDATION.REQUIRED'| translate}}
我解决了这个问题:

countries=[]作为数组
过滤国家:可见;
恩戈尼尼特(){
this.startDate.setFullYear(this.startDate.getFullYear()-18);
这个.buildForm();
this.filteredCountries=this.personalForm.controls['country'].valueChanges
.烟斗(
startWith(“”),
映射(值=>this.\u过滤器(值))
);
i18niscocountries.registerLocale(require(“i18n iso-countries/langs/en.json”);
i18niscocountries.registerLocale(require(“i18n iso countries/langs/de.json”);
this.currentLanguage=this.translateService.currentLang;
indexedArray=i18nIsoCountries.getNames(this.currentLanguage);
for(输入indexedArray){
让值=indexedArray[键];
这个。国家。推动(价值);
}
}
private_过滤器(值:string):string[]{
var滤波值;
如果(值){
filterValue=value.toLowerCase();
}否则{
filterValue=“”;
}
返回此.countries.filter(option=>option.toLowerCase().startsWith(filterValue));
}
ngAfterContentChecked(){
this.cdRef.detectChanges();
if(this.currentLanguage!=this.translateService.currentLang){
indexedArray=i18nIsoCountries.getNames(this.translateService.currentLang);
这个国家=[];
for(输入indexedArray){
让值=indexedArray[键];
这个。国家。推动(价值);
}
this.currentLanguage=this.translateService.currentLang;
this.personalForm.get('country').updateValueAndValidity();
}
}
以及html部分:


{{option}}
{{'REGISTRATION.COUNTRY'| translate}}{{'VALIDATION.REQUIRED'| translate}}

没有人知道吗?我正在考虑将其作为一个键值对来执行,并希望像我所说的那样暂时保存它,但是函数
getNames(lang:string):i18nIsoCountries.LocalizedCountryNames
只是将其作为字符串提供,即使它的输出是一个键值对也没有人有主意?我正在考虑将其作为键值对进行操作,并希望像我所说的那样暂时保存,但函数
getNames(lang:string):i18nIsoCountries.LocalizedCountryNames
仅将其作为字符串提供,即使它是输出
    {
    "countries": [
    {"name": "Afghanistan", "code": "AF"},
    {"name": "Åland Islands", "code": "AX"} ]
    }