使用角度平移开关更改数据表界面语言

问题描述 投票:0回答:1

在我的angularjs应用程序中,我使用angular translate进行更改语言

$scope.changeLanguage = function (langKey) {
    $translate.use(langKey);
    tmhDynamicLocale.set(langKey);
};

app.config(function (tmhDynamicLocaleProvider) {
    tmhDynamicLocaleProvider.localeLocationPattern('bower_components_steora/angular-i18n/angular-locale_{{locale}}.js');
});

在HTML中,我为选定的lang调用函数,并将我的json设置为已翻译的项目。

<div class="jezik">
     <a class="languageSelect" ng-click="changeLanguage('hr')" translate="BUTTON_LANG_HR"></a> | 
     <a class="languageSelect" ng-click="changeLanguage('en')" translate="BUTTON_LANG_EN"></a> | 
     <a class="languageSelect" ng-click="changeLanguage('es')" translate="BUTTON_LANG_ESP"></a> | 
     <a class="languageSelect" ng-click="changeLanguage('de')" translate="BUTTON_LANG_DE"></a> | 
     <a class="languageSelect" ng-click="changeLanguage('it')" translate="BUTTON_LANG_IT"></a> | 
     <a class="languageSelect" ng-click="changeLanguage('fr')" translate="BUTTON_LANG_FR"></a>
</div>

我的问题是,如何更改angular datatables界面语言与应用程序语言相同?当我更改我的应用程序语言时,我需要更改和数据表语言,我的意思是“显示条目”,“搜索:”,“显示20个条目中的1到10个”等。

我找到了this,但如何在角度翻译语言改变的同一次点击中更改数据表语言?

我也发现了这个plnkr,但我需要不仅在一个州进行全球变化。 Thnx和sry我的英语

javascript jquery angularjs angular-datatables
1个回答
0
投票

我做功能,并传递翻译项目。检查keylocalstorage并提供所选语言的数据

function selectedLanguageLocalStorage(localStorage) {
for (key in localStorage) {
    if (key == "NG_TRANSLATE_LANG_KEY"){
        langKey = localStorage[key];
        if (langKey == "en") {
            var language = {
                "sEmptyTable":     "No data available in table",
                "sInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",
                "sInfoEmpty":      "Showing 0 to 0 of 0 entries",
                "sInfoFiltered":   "(filtered from _MAX_ total entries)",
                "sInfoPostFix":    "",
                "sInfoThousands":  ",",
                "sLengthMenu":     "Show _MENU_ entries",
                "sLoadingRecords": "Loading...",
                "sProcessing":     "Processing...",
                "sSearch":         "Search:",
                "sZeroRecords":    "No matching records found",
                "oPaginate": {
                    "sFirst":    "First",
                    "sLast":     "Last",
                    "sNext":     "Next",
                    "sPrevious": "Previous"
                },
                "oAria": {
                    "sSortAscending":  ": activate to sort column ascending",
                    "sSortDescending": ": activate to sort column descending"
                }
            }
        }else if (langKey == "it"){
            var language = {
                "sEmptyTable":     "Nessun dato presente nella tabella",
                "sInfo":           "Vista da _START_ a _END_ di _TOTAL_ elementi",
                "sInfoEmpty":      "Vista da 0 a 0 di 0 elementi",
                "sInfoFiltered":   "(filtrati da _MAX_ elementi totali)",
                "sInfoPostFix":    "",
                "sInfoThousands":  ".",
                "sLengthMenu":     "Visualizza _MENU_ elementi",
                "sLoadingRecords": "Caricamento...",
                "sProcessing":     "Elaborazione...",
                "sSearch":         "Cerca:",
                "sZeroRecords":    "La ricerca non ha portato alcun risultato.",
                "oPaginate": {
                    "sFirst":      "Inizio",
                    "sPrevious":   "Precedente",
                    "sNext":       "Successivo",
                    "sLast":       "Fine"
                },
                "oAria": {
                    "sSortAscending":  ": attiva per ordinare la colonna in ordine crescente",
                    "sSortDescending": ": attiva per ordinare la colonna in ordine decrescente"
                }
            }
        }
        else if (langKey == "de"){
            var language = {
                "sEmptyTable":      "Keine Daten in der Tabelle vorhanden",
                "sInfo":            "_START_ bis _END_ von _TOTAL_ Einträgen",
                "sInfoEmpty":       "0 bis 0 von 0 Einträgen",
                "sInfoFiltered":    "(gefiltert von _MAX_ Einträgen)",
                "sInfoPostFix":     "",
                "sInfoThousands":   ".",
                "sLengthMenu":      "_MENU_ Einträge anzeigen",
                "sLoadingRecords":  "Wird geladen...",
                "sProcessing":      "Bitte warten...",
                "sSearch":          "Suchen",
                "sZeroRecords":     "Keine Einträge vorhanden.",
                "oPaginate": {
                    "sFirst":       "Erste",
                    "sPrevious":    "Zurück",
                    "sNext":        "Nächste",
                    "sLast":        "Letzte"
                },
                "oAria": {
                    "sSortAscending":  ": aktivieren, um Spalte aufsteigend zu sortieren",
                    "sSortDescending": ": aktivieren, um Spalte absteigend zu sortieren"
                },
                select: {
                        rows: {
                        _: '%d Zeilen ausgewählt',
                        0: 'Zum Auswählen auf eine Zeile klicken',
                        1: '1 Zeile ausgewählt'
                        }
                }
            }
        }
        else if (langKey == "es"){
            var language = {
                "sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_ registros",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningún dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "Buscar:",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Último",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                },
                "oAria": {
                    "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
                    "sSortDescending": ": Activar para ordenar la columna de manera descendente"
                }
            }
        }
        else if (langKey == "fr"){
            var language = {
                "sProcessing":     "Traitement en cours...",
                "sSearch":         "Rechercher&nbsp;:",
                "sLengthMenu":     "Afficher _MENU_ &eacute;l&eacute;ments",
                "sInfo":           "Affichage de l'&eacute;l&eacute;ment _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
                "sInfoEmpty":      "Affichage de l'&eacute;l&eacute;ment 0 &agrave; 0 sur 0 &eacute;l&eacute;ment",
                "sInfoFiltered":   "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
                "sInfoPostFix":    "",
                "sLoadingRecords": "Chargement en cours...",
                "sZeroRecords":    "Aucun &eacute;l&eacute;ment &agrave; afficher",
                "sEmptyTable":     "Aucune donn&eacute;e disponible dans le tableau",
                "oPaginate": {
                    "sFirst":      "Premier",
                    "sPrevious":   "Pr&eacute;c&eacute;dent",
                    "sNext":       "Suivant",
                    "sLast":       "Dernier"
                },
                "oAria": {
                    "sSortAscending":  ": activer pour trier la colonne par ordre croissant",
                    "sSortDescending": ": activer pour trier la colonne par ordre d&eacute;croissant"
                }
            }
        }
        else if (langKey == "hr"){
            var language = {
                "sEmptyTable":      "Nema podataka u tablici",
                "sInfo":            "Prikazano _START_ do _END_ od _TOTAL_ rezultata",
                "sInfoEmpty":       "Prikazano 0 do 0 od 0 rezultata",
                "sInfoFiltered":    "(filtrirano iz _MAX_ ukupnih rezultata)",
                "sInfoPostFix":     "",
                "sInfoThousands":   ",",
                "sLengthMenu":      "Prikaži _MENU_ rezultata po stranici",
                "sLoadingRecords":  "Dohvaćam...",
                "sProcessing":      "Obrađujem...",
                "sSearch":          "Pretraži:",
                "sZeroRecords":     "Ništa nije pronađeno",
                "oPaginate": {
                    "sFirst":       "Prva",
                    "sPrevious":    "Nazad",
                    "sNext":        "Naprijed",
                    "sLast":        "Zadnja"
                },
                "oAria": {
                    "sSortAscending":  ": aktiviraj za rastući poredak",
                    "sSortDescending": ": aktiviraj za padajući poredak"
                }
            }
        }
    }
}
return language;
};    

在DTOptions中我称之为函数

vm.dtOptions = DTOptionsBuilder.newOptions().withLanguage(selectedLanguageLocalStorage(localStorage))

这样,我需要将相同的数据放到我使用数据表的所有ctrl中。当更改语言时,我需要刷新以获取此翻译数据。如果有人有解决方案,请写信。日Thnx

© www.soinside.com 2019 - 2024. All rights reserved.