[英]Is it possible to dynamically add ag-grid localisations?
I am using the AgGridModule
Angular wrapper of the ag-grid
framework. 我正在使用ag-grid
框架的AgGridModule
Angular包装器。 My application is an Angular AOT application which handles localisation using the ngx-translate library (which dynamically loads translation data files on page load, for the currently selected language). 我的应用程序是Angular AOT应用程序,它使用ngx-translate库处理本地化(对于当前选择的语言,该库在页面加载时动态加载翻译数据文件)。 This means that translations are only available asynchronously. 这意味着翻译只能异步使用。 As such I cannot just set the localeText
property in gridOptions
( as recommended ) since I don't have the texts before generating the grid. 因此我不能只设置localeText
财产gridOptions
( 推荐 ),因为我没有产生前栅格的文本。
Does anyone know how to handle this scenario? 有谁知道如何处理这种情况? Ideally I would just assign an RxJS Observable
to the localeText
property, which would send the appropriate texts object when ready, but this does not seem to work currently. 理想情况下,我只是将RxJS Observable
分配给localeText
属性,该属性将在准备好后发送适当的texts对象,但是目前似乎无法正常工作。
This can be done by providing your own localeTextFunc
. 这可以通过提供您自己的localeTextFunc
来完成。 That function takes the key from the grid and uses a translate function (ngx-translate in our case) outside of the grid for doing the translation. 该函数从网格中获取键,并在网格外部使用转换函数(在本例中为ngx-translate)进行转换。 If no match is found, then the default value should be returned (which is the English value for the grid, the grids default language). 如果找不到匹配项,则应返回默认值(这是网格的英语值,即网格的默认语言)。
this.gridOptions = {
localeTextFunc: (key: string, defaultValue: string) => {
// look the value up. using the ngx translate service
const data = this.translate.instant(key);
return data === key ? defaultValue : data;
}
};
Inject TranslateService
as translate from '@ngx-translate/core' to use the synchronous translate.instant()
method. 从'@ ngx-translate / core'注入TranslateService
作为转换,以使用sync.instant translate.instant()
方法。 But make sure the translations have been loaded before calling instant mthod. 但是,在调用Instant Mthod之前,请确保已加载翻译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.