Implemented javascript side localization.

pull/179/head
Halil İbrahim Kalkan 7 years ago
parent 5c9b3bcf8e
commit 21914f50cc

@ -66,7 +66,8 @@ namespace AbpDesk.Web.Mvc
{
options.ScriptBundles.Add("GlobalScripts", new[]
{
"/AbpServiceProxies/GetAll?_v=" + DateTime.Now.Ticks
"/Abp/ApplicationConfigurationScript?_v=" + DateTime.Now.Ticks,
"/Abp/ServiceProxyScript?_v=" + DateTime.Now.Ticks
});
});

@ -0,0 +1,22 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
{
[Route("api/abp/application-configuration")]
public class AbpApplicationConfigurationController : AbpController
{
private readonly IApplicationConfigurationBuilder _configurationBuilder;
public AbpApplicationConfigurationController(IApplicationConfigurationBuilder configurationBuilder)
{
_configurationBuilder = configurationBuilder;
}
[HttpGet]
public Task<ApplicationConfigurationDto> Get()
{
return _configurationBuilder.Get();
}
}
}

@ -0,0 +1,45 @@
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Json;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
{
[Area("Abp")]
[Route("Abp/ApplicationConfigurationScript")]
public class AbpApplicationConfigurationScriptController : AbpController
{
private readonly IApplicationConfigurationBuilder _configurationBuilder;
private readonly IJsonSerializer _jsonSerializer;
public AbpApplicationConfigurationScriptController(
IApplicationConfigurationBuilder configurationBuilder,
IJsonSerializer jsonSerializer)
{
_configurationBuilder = configurationBuilder;
_jsonSerializer = jsonSerializer;
}
[HttpGet]
[Produces("text/javascript", "text/plain")]
public async Task<string> Get()
{
var config = await _configurationBuilder.Get();
return CreateAbpExtendScript(config);
}
private string CreateAbpExtendScript(ApplicationConfigurationDto config)
{
var script = new StringBuilder();
script.AppendLine("(function(){");
script.AppendLine($"$.extend(true, abp, {_jsonSerializer.Serialize(config, indented: Debugger.IsAttached)})");
script.Append("})();");
return script.ToString();
}
}
}

@ -1,24 +0,0 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
{
public class ApplicationConfigurationController : AbpController
{
private readonly IApplicationConfigurationBuilder _configurationBuilder;
public ApplicationConfigurationController(IApplicationConfigurationBuilder configurationBuilder)
{
_configurationBuilder = configurationBuilder;
}
public async Task<JsonResult> GetAll()
{
//TODO: 1. Make an API
//TODO: 2. Make a script generation controller
var userConfig = await _configurationBuilder.Get();
return Json(userConfig);
}
}
}

@ -5,11 +5,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ProxyScripting
{
//TODO: abp area?
//TODO: [DisableAuditing]
public class AbpServiceProxiesController : AbpController
[Area("Abp")]
[Route("Abp/ServiceProxyScript")]
public class AbpServiceProxyScriptController : AbpController
{
private readonly IProxyScriptManager _proxyScriptManager;
public AbpServiceProxiesController(IProxyScriptManager proxyScriptManager)
public AbpServiceProxyScriptController(IProxyScriptManager proxyScriptManager)
{
_proxyScriptManager = proxyScriptManager;
}

@ -11,6 +11,7 @@
"Roles": "Roles",
"Close": "Close",
"Save": "Save",
"Password": "Password"
"Password": "Password",
"UserDeletionConfirmationMessage": "User '{0}' will be deleted. Do you confirm that?"
}
}

@ -11,6 +11,7 @@
"Roles": "Roller",
"Close": "Kapat",
"Save": "Kaydet",
"Password": "Şifre"
"Password": "Şifre",
"UserDeletionConfirmationMessage": "{0} kullanıcısı silinecektir. Onaylıyor musunuz?"
}
}

@ -1,5 +1,6 @@
$(function () {
var _identityUserAppService = volo.abp.identity.identityUser;
var _localize = abp.localization.getResource('AbpIdentityWeb');
var dataTable = $('#IdentityUsersTable').DataTable({
order: [[1, "asc"]],
@ -82,8 +83,9 @@
$('#IdentityUsersTable').on('click', '.delete-user', function () {
var id = $(this).data('id');
var userName = $(this).data('userName');
if (confirm('Are you sure you want to delete?')) {
if (confirm(_localize('UserDeletionConfirmationMessage', userName))) {
_identityUserAppService.delete(id).done(function () {
dataTable.ajax.reload();
});
@ -160,9 +162,11 @@ $.fn.serializeFormToObject = function () {
return;
}
var currentLanguage = 'English'; //TODO: Get from current culture!
$.extend(true, $.fn.dataTable.defaults, {
language: {
url: '/modules/identity/libs/datatables/localizations/' + abp.localization.currentCulture.displayNameEnglish + '.json'
url: '/modules/identity/libs/datatables/localizations/' + currentLanguage + '.json'
},
lengthMenu: [5, 10, 25, 50, 100, 250, 500],
pageLength: 10,

@ -37,7 +37,7 @@ namespace Volo.Abp.Json.Newtonsoft
if (camelCase)
{
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.ContractResolver = new CamelCaseExceptDictionaryKeysResolver();
}
if (indented)
@ -47,5 +47,17 @@ namespace Volo.Abp.Json.Newtonsoft
return settings;
}
private class CamelCaseExceptDictionaryKeysResolver : CamelCasePropertyNamesContractResolver
{
protected override JsonDictionaryContract CreateDictionaryContract(Type objectType)
{
var contract = base.CreateDictionaryContract(objectType);
contract.DictionaryKeyResolver = propertyName => propertyName;
return contract;
}
}
}
}
Loading…
Cancel
Save