Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/features/romanize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Romanize

Trqnform non-latin letter languages to their roman equivalent

- **Menu:** Tools → Romanize...
- **Shortcut:** Configurable

<!-- Screenshot: Romanize window -->
![Romanize](../screenshots/romanize.png)

## How to Use

1. Open **Tools → Romanize...**.
2. Check the languages which you would like to romanize
3. Click **OK**.

Subtitle Edit rewrites the text in in latin-letter equivalence. Timing, text, formatting, and comments are not changed.

## Options

- **Merge** — Merges source for single line result
- **Position** — The position of the romanized text in reference to the original text

## Keyboard Shortcuts

| Key | Action |
|-----|--------|
| Enter | Apply |
| Escape | Close / Cancel |
| F1 | Open help |
Binary file added docs/screenshots/romanize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/libse/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions src/libse/Romanize/IRomanizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace Nikse.SubtitleEdit.Core.Romanize
{
public interface IRomanizer
{
private static readonly JapaneseRomanizer _Japanese = new JapaneseRomanizer();
private static readonly KoreanRomanizer _Korean = new KoreanRomanizer();
private static readonly RussianRomanizer _Russian = new RussianRomanizer();

private static IRomanizer GetRomanizerForChar(char ch)
{
if (_Japanese.IsValid(ch)) return _Japanese;
if (_Korean.IsValid(ch)) return _Korean;
if (_Russian.IsValid(ch)) return _Russian;

return null;
}

CultureInfo Culture { get; }

bool IsValid(char chr);
bool IsValid(string text);
string Romanize(string text);

public static string RomanizeText(string text, params CultureInfo[] exclude)
{
return RomanizeText(text, exclude as IEnumerable<CultureInfo>);
}
public static string RomanizeText(string text, IEnumerable<CultureInfo> exclude)
{
if (string.IsNullOrEmpty(text))
{
return string.Empty;
}

var sb = new System.Text.StringBuilder(text.Length);
var i = 0;
while (i < text.Length)
{
var romanizer = GetRomanizerForChar(text[i]);
if (romanizer == null || exclude.Contains(romanizer.Culture) is false)
{
sb.Append(text[i]);
i++;
continue;
}

var start = i;
while (i < text.Length && GetRomanizerForChar(text[i]) == romanizer)
{
i++;
}

sb.Append(romanizer.Romanize(text.Substring(start, i - start)));
}

return sb.ToString();
}
}
}
Loading