diff --git a/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj b/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj index f64db23fa..906c4466d 100644 --- a/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj +++ b/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj @@ -69,6 +69,7 @@ + @@ -142,6 +143,10 @@ {66FCCD76-2761-47E3-8D11-B45D0001DDAA} Orchard.Autoroute + + {6f759635-13d7-4e94-bcc9-80445d63f117} + Orchard.Tokens + diff --git a/src/Orchard.Web/Modules/Orchard.Localization/Providers/ContentLocalizationTokens.cs b/src/Orchard.Web/Modules/Orchard.Localization/Providers/ContentLocalizationTokens.cs new file mode 100644 index 000000000..6563337b0 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Localization/Providers/ContentLocalizationTokens.cs @@ -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("Content") + .Token("Culture", x => _localizationService.GetContentCulture(x)) + .Chain("Culture", "Culture", x => CultureInfo.GetCultureInfo(_localizationService.GetContentCulture(x))) + ; + + context.For("Culture") + .Token("Name", info => info.Name) + .Token("TwoLetterISOLanguageName", info => info.TwoLetterISOLanguageName) + ; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Tokens/Providers/ContentTokens.cs b/src/Orchard.Web/Modules/Orchard.Tokens/Providers/ContentTokens.cs index 2fc85a5b3..257394d88 100644 --- a/src/Orchard.Web/Modules/Orchard.Tokens/Providers/ContentTokens.cs +++ b/src/Orchard.Web/Modules/Orchard.Tokens/Providers/ContentTokens.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using System.Web; using System.Web.Mvc;