mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Starting to add screens for transliteration
This commit is contained in:
18
src/Orchard.Web/Modules/Orchard.Localization/AdminMenu.cs
Normal file
18
src/Orchard.Web/Modules/Orchard.Localization/AdminMenu.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
[OrchardFeature("Orchard.Localization.Transliteration")]
|
||||
public class AdminMenu : INavigationProvider {
|
||||
public Localizer T { get; set; }
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder
|
||||
.Add(T("Settings"), menu => menu
|
||||
.Add(T("Transliteration"), "10.0", subMenu => subMenu.Action("Index", "TransliterationAdmin", new { area = "Orchard.Localization" })
|
||||
.Add(T("Settings"), "10.0", item => item.Action("Index", "TransliterationAdmin", new { area = "Orchard.Localization" }).LocalNav())
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Localization.ViewModels;
|
||||
using Orchard.UI.Admin;
|
||||
|
||||
namespace Orchard.Localization.Controllers {
|
||||
[OrchardFeature("Orchard.Localization.Transliteration")]
|
||||
[Admin]
|
||||
public class TransliterationAdminController : Controller {
|
||||
private readonly ITransliterationService _transliterationService;
|
||||
|
||||
public TransliterationAdminController(ITransliterationService transliterationService,
|
||||
IShapeFactory shapeFactory) {
|
||||
_transliterationService = transliterationService;
|
||||
T = NullLocalizer.Instance;
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
dynamic Shape { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
|
||||
var specifications = _transliterationService.GetSpecifications();
|
||||
|
||||
var viewModel = Shape.ViewModel()
|
||||
.Specifications(specifications);
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public ActionResult Import() {
|
||||
var viewModel = new ImportTransliterationViewModel();
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Environment.Extensions;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
public class Migrations : DataMigrationImpl {
|
||||
@@ -25,4 +26,20 @@ namespace Orchard.Localization {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Localization.Transliteration")]
|
||||
public class TransliteratoinMigrations : DataMigrationImpl {
|
||||
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("TransliterationSpecificationRecord",
|
||||
table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
||||
.Column<string>("CultureFrom")
|
||||
.Column<string>("CultureTo")
|
||||
.Column<string>("Rules", c => c.Unlimited())
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using Orchard.Data.Conventions;
|
||||
using Orchard.Environment.Extensions;
|
||||
|
||||
namespace Orchard.Localization.Models {
|
||||
[OrchardFeature("Orchard.Localization.Transliteration")]
|
||||
public class TransliterationSpecificationRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual int LCIDFrom { get; set; }
|
||||
public virtual int LCIDTo { get; set; }
|
||||
public virtual string CultureFrom { get; set; }
|
||||
public virtual string CultureTo { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string Rules { get; set; }
|
||||
|
||||
@@ -68,7 +68,9 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\TransliterationAdminController.cs" />
|
||||
<Compile Include="Controllers\CutlureSelectorController.cs" />
|
||||
<Compile Include="Models\TransliterationSpecificationRecord.cs" />
|
||||
<Compile Include="Providers\CultureSelectorSelector.cs" />
|
||||
@@ -87,13 +89,14 @@
|
||||
<Compile Include="Routes.cs" />
|
||||
<Compile Include="Services\ICultureStorageProvider.cs" />
|
||||
<Compile Include="Services\ILocalizationService.cs" />
|
||||
<Compile Include="Services\ITransliterationServices.cs" />
|
||||
<Compile Include="Services\ITransliterationService.cs" />
|
||||
<Compile Include="Services\LocalizationDateTimeFormatProvider.cs" />
|
||||
<Compile Include="Services\LocalizationService.cs" />
|
||||
<Compile Include="Services\TransliterationServices.cs" />
|
||||
<Compile Include="Services\TransliterationService.cs" />
|
||||
<Compile Include="ViewModels\AddLocalizationViewModel.cs" />
|
||||
<Compile Include="ViewModels\ContentLocalizationsViewModel.cs" />
|
||||
<Compile Include="ViewModels\EditLocalizationViewModel.cs" />
|
||||
<Compile Include="ViewModels\ImportTransliterationViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
@@ -142,6 +145,12 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\UICultureSelector.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\TransliterationAdmin\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\TransliterationAdmin\Import.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Localization.Models;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
public interface ITransliterationService : IDependency {
|
||||
string Convert(string value, int transliterationSpecificationId);
|
||||
IEnumerable<TransliterationSpecificationRecord> GetSpecifications();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
namespace Orchard.Localization.Services {
|
||||
public interface ITransliterationServices : IDependency {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.NaturalLanguage.Tools;
|
||||
using System.Text;
|
||||
using Orchard.Data;
|
||||
@@ -7,11 +9,11 @@ using Orchard.Localization.Models;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
[OrchardFeature("Orchard.Localization.Transliteration")]
|
||||
public class TransliterationServices : ITransliterationServices {
|
||||
public class TransliterationService : ITransliterationService {
|
||||
private readonly IRepository<TransliterationSpecificationRecord> _transliterationRepository;
|
||||
private readonly bool fOnlyMetadata = false;
|
||||
|
||||
public TransliterationServices(IRepository<TransliterationSpecificationRecord> transliterationRepository) {
|
||||
public TransliterationService(IRepository<TransliterationSpecificationRecord> transliterationRepository) {
|
||||
_transliterationRepository = transliterationRepository;
|
||||
}
|
||||
|
||||
@@ -32,6 +34,10 @@ namespace Orchard.Localization.Services {
|
||||
transliteratorRuleTraceList);
|
||||
}
|
||||
|
||||
public IEnumerable<TransliterationSpecificationRecord> GetSpecifications() {
|
||||
return _transliterationRepository.Table.ToList();
|
||||
}
|
||||
|
||||
private TransliteratorSpecification GetSpecification(TransliterationSpecificationRecord record) {
|
||||
using (TextReader specificationReader = new StringReader(record.Rules)) {
|
||||
return TransliteratorSpecification.FromSpecificationFile(specificationReader, fOnlyMetadata);
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Orchard.Localization.ViewModels {
|
||||
public class ImportTransliterationViewModel {
|
||||
public string Rules { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
@model Orchard.Localization.ViewModels.ImportTransliterationViewModel
|
||||
|
||||
@{
|
||||
Layout.Title = T("Import Transliteration").Text;
|
||||
}
|
||||
|
||||
@using(Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
<fieldset>
|
||||
|
||||
<textarea rows="25" cols="80" name="Rules">@Model.Rules</textarea>
|
||||
<span class="hint">@T("[Input]")</span>
|
||||
<span class="hint">@T("// Insert a several-word description of the module’s input.")</span>
|
||||
<span class="hint">@T("// For example:")</span>
|
||||
<span class="hint">@T("// Romanization")</span>
|
||||
|
||||
<span class="hint">@T("[Output]")</span>
|
||||
<span class="hint">@T("// Insert a several-word description of the module’s output.")</span>
|
||||
<span class="hint">@T("// For example:")</span>
|
||||
<span class="hint">@T("// Cyrillic")</span>
|
||||
|
||||
<span class="hint">@T("[Description]")</span>
|
||||
<span class="hint">@T("// Give a several-sentence description of the module.")</span>
|
||||
|
||||
<span class="hint">@T("[Preprocess]")</span>
|
||||
<span class="hint">@T("// If you need to preprocess your input before applying")</span>
|
||||
<span class="hint">@T("// rules specify the procedure here.")</span>
|
||||
<span class="hint">@T("// For example:")</span>
|
||||
<span class="hint">@T("// ToLower")</span>
|
||||
<span class="hint">@T("// ToUpper(tr-TR)")</span>
|
||||
|
||||
<span class="hint">@T("[States]")</span>
|
||||
<span class="hint">@T("// If you need any states other than the two predefined ones")</span>
|
||||
<span class="hint">@T("// (START and DEFAULT) then declare their names here.")</span>
|
||||
<span class="hint">@T("// For example:")</span>
|
||||
<span class="hint">@T("// CONSONANT")</span>
|
||||
<span class="hint">@T("// VOWEL")</span>
|
||||
|
||||
<span class="hint">@T("[FollowingContextMacros]")</span>
|
||||
<span class="hint">@T("// Insert any following context macro definitions here.")</span>
|
||||
<span class="hint">@T("// For example:")</span>
|
||||
<span class="hint">@T("// Cons b c d f g h j k l m n p q r s t v w x y z")</span>
|
||||
<span class="hint">@T("// ConsOrEnd <END> :Cons:")</span>
|
||||
<span class="hint">@T("// Vowel a e i o u")</span>
|
||||
<span class="hint">@T("// VowelAtEnd a<END> e<END> i<END> o<END> u<END>")</span>
|
||||
|
||||
<span class="hint">@T("[EscapeSpanDelimiters]")</span>
|
||||
<span class="hint">@T("// If you need to be able to prevent spans of the input")</span>
|
||||
<span class="hint">@T("// from being processed you can specify one pair of strings")</span>
|
||||
<span class="hint">@T("// to indicate the beginning and end of such escaped spans.")</span>
|
||||
<span class="hint">@T("// For example:")</span>
|
||||
<span class="hint">@T("// { }")</span>
|
||||
<span class="hint">@T("// /* */")</span>
|
||||
|
||||
<span class="hint">@T("[Rules]")</span>
|
||||
<span class="hint">@T("// List your rules here. For example:")</span>
|
||||
<span class="hint">@T("// a –> x")</span>
|
||||
<span class="hint">@T("// a(<END>) –> y")</span>
|
||||
<span class="hint">@T("// [START] fa –> z [VOWEL]")</span>
|
||||
</fieldset>
|
||||
|
||||
<input class="button" type="submit" value="@T("Import")" />
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
@using System.Globalization
|
||||
@using Orchard.Localization.Models
|
||||
@{
|
||||
Layout.Title = T("Transliteration Settings");
|
||||
|
||||
var currentSpecifications = (IEnumerable<TransliterationSpecificationRecord>)Model.Specifications;
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
|
||||
if (currentSpecifications.Any()) {
|
||||
<div class="actions" style="margin-bottom: 15px;"><a class="add button primaryAction" href="#">@T("Register a new specification")</a></div>
|
||||
<table class="items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T("Culture From")</th>
|
||||
<th scope="col">@T("Culture To")</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@foreach (var currentSpecification in currentSpecifications) {
|
||||
CultureInfo cultureInfoFrom = CultureInfo.GetCultureInfo(currentSpecification.CultureFrom);
|
||||
CultureInfo cultureInfoTo = CultureInfo.GetCultureInfo(currentSpecification.CultureTo);
|
||||
|
||||
<tr>
|
||||
<td>@cultureInfoFrom.DisplayName</td>
|
||||
<td>@cultureInfoTo.DisplayName</td>
|
||||
<td>
|
||||
@*<a href="@Url.RemoveProviderConfiguration(currentProvider.Id)">@T("Remove")</a>*@
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
<span class="hint">@T("A provider identifier may not be shown if not supplied by an internal library. Also A key and secret are not required for every mechanism")</span>
|
||||
}
|
||||
else {
|
||||
<p class="nospecifications">@T("There are no specifications registered. Why not <a href=\"{0}\">register one</a>?", "#")</p>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user