mirror of https://github.com/abpframework/abp.git
17 changed files with 143 additions and 52 deletions
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Localization |
||||
|
{ |
||||
|
public class LocalizationResourceDictionary : Dictionary<Type, LocalizationResource> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -1,9 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace Volo.Abp.Localization |
|
||||
{ |
|
||||
public class LocalizationResourceList : List<LocalizationResource> |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,24 +1,50 @@ |
|||||
using JetBrains.Annotations; |
using System.Collections.Generic; |
||||
|
using JetBrains.Annotations; |
||||
using Volo.Abp.Localization.Json; |
using Volo.Abp.Localization.Json; |
||||
|
|
||||
namespace Volo.Abp.Localization |
namespace Volo.Abp.Localization |
||||
{ |
{ |
||||
public static class LocalizationResourceListExtensions |
public static class LocalizationResourceListExtensions |
||||
{ |
{ |
||||
public static void AddJson<TResource>(this LocalizationResourceList resourceList, [NotNull] string defaultCultureName) |
public static void AddJson<TResource>([NotNull] this LocalizationResourceDictionary resourceDictionary, [NotNull] string defaultCultureName) |
||||
{ |
{ |
||||
var type = typeof(TResource); |
Check.NotNull(resourceDictionary, nameof(resourceDictionary)); |
||||
|
Check.NotNull(defaultCultureName, nameof(defaultCultureName)); |
||||
resourceList.Add( |
|
||||
new LocalizationResource( |
var resourceType = typeof(TResource); |
||||
type, |
|
||||
defaultCultureName, |
if (resourceDictionary.ContainsKey(resourceType)) |
||||
new JsonEmbeddedFileLocalizationDictionaryProvider( |
{ |
||||
type.Assembly, |
throw new AbpException("There is already a resource with given type: " + resourceType.AssemblyQualifiedName); |
||||
type.Namespace |
} |
||||
) |
|
||||
|
resourceDictionary[resourceType] = new LocalizationResource( |
||||
|
resourceType, |
||||
|
defaultCultureName, |
||||
|
new JsonEmbeddedFileLocalizationDictionaryProvider( |
||||
|
resourceType.Assembly, |
||||
|
resourceType.Namespace |
||||
) |
) |
||||
); |
); |
||||
} |
} |
||||
|
|
||||
|
public static void ExtendWithJson<TResource, TResourceExt>([NotNull] this LocalizationResourceDictionary resourceDictionary) |
||||
|
{ |
||||
|
Check.NotNull(resourceDictionary, nameof(resourceDictionary)); |
||||
|
|
||||
|
var resourceType = typeof(TResource); |
||||
|
var resourceExtType = typeof(TResourceExt); |
||||
|
|
||||
|
var resource = resourceDictionary.GetOrDefault(resourceType); |
||||
|
if (resource == null) |
||||
|
{ |
||||
|
throw new AbpException("Can not find a resource with given type: " + resourceType.AssemblyQualifiedName); |
||||
|
} |
||||
|
|
||||
|
resource.Extensions.Add(new JsonEmbeddedFileLocalizationDictionaryProvider( |
||||
|
resourceExtType.Assembly, |
||||
|
resourceExtType.Namespace |
||||
|
)); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
@ -1,7 +1,7 @@ |
|||||
{ |
{ |
||||
"culture": "en", |
"culture": "en", |
||||
"texts": { |
"texts": { |
||||
"Hello <b>{0}</b>.": "Hello <b>{0}</b>", |
"Hello <b>{0}</b>.": "Hello <b>{0}</b>.", |
||||
"Car": "Car", |
"Car": "Car", |
||||
"CarPlural": "Cars" |
"CarPlural": "Cars" |
||||
} |
} |
||||
|
|||||
@ -1,7 +1,7 @@ |
|||||
{ |
{ |
||||
"culture": "tr", |
"culture": "tr", |
||||
"texts": { |
"texts": { |
||||
"Hello <b>{0}</b>.": "Merhaba <b>{0}</b>", |
"Hello <b>{0}</b>.": "Merhaba <b>{0}</b>.", |
||||
"Car": "Araba", |
"Car": "Araba", |
||||
"CarPlural": "Araba" |
"CarPlural": "Araba" |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.Localization.SourceExt |
||||
|
{ |
||||
|
internal sealed class LocalizationTestResourceExt |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"SeeYou": "See you" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"culture": "it", |
||||
|
"texts": { |
||||
|
"Hello <b>{0}</b>.": "Ciao <b>{0}</b>.", |
||||
|
"Car": "Auto", |
||||
|
"SeeYou": "Ci vediamo" |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue