Adding Localization Tokens to localization module.

This commit is contained in:
Nicholas Mayne
2015-02-18 16:48:04 +00:00
parent a60b91e610
commit e1a9999382
3 changed files with 46 additions and 0 deletions

View File

@@ -69,6 +69,7 @@
<Compile Include="Controllers\AdminCultureSelectorController.cs" />
<Compile Include="Helpers\ContextHelpers.cs" />
<Compile Include="Models\TransliterationSpecificationRecord.cs" />
<Compile Include="Providers\ContentLocalizationTokens.cs" />
<Compile Include="Selectors\ContentCultureSelector.cs" />
<Compile Include="Selectors\RouteCultureSelector.cs" />
<Compile Include="Selectors\BrowserCultureSelector.cs" />
@@ -142,6 +143,10 @@
<Project>{66FCCD76-2761-47E3-8D11-B45D0001DDAA}</Project>
<Name>Orchard.Autoroute</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
<Project>{6f759635-13d7-4e94-bcc9-80445d63f117}</Project>
<Name>Orchard.Tokens</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="web.config" />

View File

@@ -0,0 +1,40 @@
using System.Globalization;
using Orchard.ContentManagement;
using Orchard.Localization.Services;
using Orchard.Tokens;
namespace Orchard.Localization.Providers {
public class ContentLocalizationTokens : ITokenProvider {
private readonly ILocalizationService _localizationService;
public ContentLocalizationTokens(ILocalizationService localizationService) {
_localizationService = localizationService;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public void Describe(DescribeContext context) {
context.For("Content", T("Content Items"), T("Content Items"))
.Token("Culture", T("Culture"), T("The culture of the content item"), "Culture")
;
context.For("Culture", T("Culture"), T("Tokens for culture"))
.Token("Name", T("Name"), T("Gets the culture name in the format languagecode2-country/regioncode2."), "Text")
.Token("TwoLetterISOLanguageName", T("Two Letter ISO Language Name"), T("Gets the ISO 639-1 two-letter code for the language of the current CultureInfo."), "Text");
}
public void Evaluate(EvaluateContext context) {
context.For<IContent>("Content")
.Token("Culture", x => _localizationService.GetContentCulture(x))
.Chain("Culture", "Culture", x => CultureInfo.GetCultureInfo(_localizationService.GetContentCulture(x)))
;
context.For<CultureInfo>("Culture")
.Token("Name", info => info.Name)
.Token("TwoLetterISOLanguageName", info => info.TwoLetterISOLanguageName)
;
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;