-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CHANGE - Changed how splitting regexes are configured to supports scopes + more.
- Loading branch information
randoman
committed
Sep 3, 2019
1 parent
ccb4bc4
commit 20a1a5a
Showing
20 changed files
with
292 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ public override string Version | |
{ | ||
get | ||
{ | ||
return "4.1.0"; | ||
return "4.2.0"; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 28 additions & 10 deletions
38
src/XUnity.AutoTranslator.Plugin.Core/Parsing/ParserResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,56 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace XUnity.AutoTranslator.Plugin.Core.Parsing | ||
{ | ||
internal class ParserResult | ||
{ | ||
public ParserResult( string originalText, string template, bool cacheCombinedResult, bool persistCombinedResult, bool persistTokenResult, Dictionary<string, string> args ) | ||
public ParserResult( string originalText, string template, bool allowPartialTranslation, bool cacheCombinedResult, bool persistCombinedResult, bool persistTokenResult, Dictionary<string, string> args ) | ||
{ | ||
OriginalText = originalText; | ||
Template = template; | ||
AllowPartialTranslation = allowPartialTranslation; | ||
CacheCombinedResult = cacheCombinedResult; | ||
PersistCombinedResult = persistCombinedResult; | ||
PersistTokenResult = persistTokenResult; | ||
Arguments = args; | ||
} | ||
|
||
public string OriginalText { get; private set; } | ||
public string OriginalText { get; } | ||
|
||
public string Template { get; private set; } | ||
public Dictionary<string, string> Arguments { get; private set; } | ||
public string Template { get; } | ||
public Dictionary<string, string> Arguments { get; } | ||
|
||
public bool AllowPartialTranslation { get; } | ||
|
||
public bool CacheCombinedResult { get; } | ||
|
||
public bool PersistCombinedResult { get; private set; } | ||
public bool PersistCombinedResult { get; } | ||
|
||
public bool PersistTokenResult { get; private set; } | ||
public bool PersistTokenResult { get; } | ||
|
||
public string Untemplate( Dictionary<string, string> arguments ) | ||
{ | ||
string result = Template; | ||
foreach( var kvp in arguments ) | ||
// This is really not a nice fix... | ||
if( arguments.Count > 9 ) | ||
{ | ||
var result = new StringBuilder( Template ); | ||
foreach( var kvp in arguments.OrderByDescending( x => x.Key.Length ) ) | ||
{ | ||
result = result.Replace( kvp.Key, kvp.Value ); | ||
} | ||
return result.ToString(); | ||
} | ||
else | ||
{ | ||
result = result.Replace( kvp.Key, kvp.Value ); | ||
var result = new StringBuilder( Template ); | ||
foreach( var kvp in arguments ) | ||
{ | ||
result = result.Replace( kvp.Key, kvp.Value ); | ||
} | ||
return result.ToString(); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 57 additions & 4 deletions
61
src/XUnity.AutoTranslator.Plugin.Core/Parsing/RegexTranslationSplitter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,73 @@ | ||
using System.Text.RegularExpressions; | ||
using XUnity.Common.Logging; | ||
|
||
namespace XUnity.AutoTranslator.Plugin.Core.Parsing | ||
{ | ||
internal class RegexTranslationSplitter | ||
{ | ||
public RegexTranslationSplitter( string regex, string translation ) | ||
public RegexTranslationSplitter( string key, string value ) | ||
{ | ||
CompiledRegex = new Regex( regex ); | ||
Translation = translation; | ||
Original = regex; | ||
Key = key; | ||
Value = value; | ||
|
||
// remove sr: | ||
if( key.StartsWith( "sr:" ) ) | ||
{ | ||
key = key.Substring( 3, key.Length - 3 ); | ||
} | ||
|
||
var startIdx = key.IndexOf( '"' ); | ||
if( startIdx == -1 ) | ||
{ | ||
// take entire string | ||
} | ||
else | ||
{ | ||
startIdx++; | ||
var endIdx = key.LastIndexOf( '"' ); | ||
if( endIdx != startIdx ) | ||
{ | ||
key = key.Substring( startIdx, endIdx - startIdx ); | ||
} | ||
} | ||
|
||
// remove sr: | ||
if( value.StartsWith( "sr:" ) ) | ||
{ | ||
value = value.Substring( 3, value.Length - 3 ); | ||
} | ||
|
||
startIdx = value.IndexOf( '"' ); | ||
if( startIdx == -1 ) | ||
{ | ||
// take entire string | ||
} | ||
else | ||
{ | ||
startIdx++; | ||
var endIdx = value.LastIndexOf( '"' ); | ||
if( endIdx != startIdx ) | ||
{ | ||
value = value.Substring( startIdx, endIdx - startIdx ); | ||
} | ||
} | ||
|
||
if( !key.StartsWith( "^" ) ) key = "^" + key; | ||
if( !key.EndsWith( "$" ) ) key = key + "$"; | ||
|
||
CompiledRegex = new Regex( key ); | ||
Original = key; | ||
Translation = value; | ||
} | ||
|
||
public Regex CompiledRegex { get; set; } | ||
|
||
public string Original { get; set; } | ||
|
||
public string Translation { get; set; } | ||
|
||
public string Key { get; set; } | ||
|
||
public string Value { get; set; } | ||
} | ||
} |
Oops, something went wrong.