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; |
|||
|
|||
namespace Volo.Abp.Localization |
|||
{ |
|||
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); |
|||
|
|||
resourceList.Add( |
|||
new LocalizationResource( |
|||
type, |
|||
defaultCultureName, |
|||
new JsonEmbeddedFileLocalizationDictionaryProvider( |
|||
type.Assembly, |
|||
type.Namespace |
|||
) |
|||
Check.NotNull(resourceDictionary, nameof(resourceDictionary)); |
|||
Check.NotNull(defaultCultureName, nameof(defaultCultureName)); |
|||
|
|||
var resourceType = typeof(TResource); |
|||
|
|||
if (resourceDictionary.ContainsKey(resourceType)) |
|||
{ |
|||
throw new AbpException("There is already a resource with given type: " + resourceType.AssemblyQualifiedName); |
|||
} |
|||
|
|||
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", |
|||
"texts": { |
|||
"Hello <b>{0}</b>.": "Hello <b>{0}</b>", |
|||
"Hello <b>{0}</b>.": "Hello <b>{0}</b>.", |
|||
"Car": "Car", |
|||
"CarPlural": "Cars" |
|||
} |
|||
|
|||
@ -1,7 +1,7 @@ |
|||
{ |
|||
"culture": "tr", |
|||
"texts": { |
|||
"Hello <b>{0}</b>.": "Merhaba <b>{0}</b>", |
|||
"Hello <b>{0}</b>.": "Merhaba <b>{0}</b>.", |
|||
"Car": "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