Notifies the users not to add duplicated phrases.
This commit is contained in:
parent
472b149020
commit
dc24de2ccb
|
@ -90,3 +90,5 @@
|
|||
"Cursor is after \"%@\"." = "Cursor is after \"%@\".";
|
||||
|
||||
"Cursor is between \"%@\" and \"%@\"." = "Cursor is between \"%@\" and \"%@\".";
|
||||
|
||||
"You are now selecting \"%@\". The phrase already exists." = "You are now selecting \"%@\". The phrase already exists.";
|
||||
|
|
|
@ -185,6 +185,16 @@ class InputState: NSObject {
|
|||
} else if (markedRange.length > kMaxMarkRangeLength) {
|
||||
return String(format: NSLocalizedString("You are now selecting \"%@\". A phrase cannot be longer than %d characters.", comment: ""), text, kMaxMarkRangeLength)
|
||||
}
|
||||
|
||||
let (exactBegin, _) = (composingBuffer as NSString).characterIndex(from: markedRange.location)
|
||||
let (exactEnd, _) = (composingBuffer as NSString).characterIndex(from: markedRange.location + markedRange.length)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
let exist = LanguageModelManager.checkIfExist(userPhrase: text, key: joined)
|
||||
if exist {
|
||||
return String(format: NSLocalizedString("You are now selecting \"%@\". The phrase already exists.", comment: ""), text)
|
||||
}
|
||||
|
||||
return String(format: NSLocalizedString("You are now selecting \"%@\". Press enter to add a new phrase.", comment: ""), text)
|
||||
}
|
||||
|
||||
|
@ -238,9 +248,18 @@ class InputState: NSObject {
|
|||
if composingBuffer.count != readings.count {
|
||||
return false
|
||||
}
|
||||
|
||||
return markedRange.length >= kMinMarkRangeLength &&
|
||||
markedRange.length <= kMaxMarkRangeLength
|
||||
if markedRange.length < kMinMarkRangeLength {
|
||||
return false
|
||||
}
|
||||
if markedRange.length > kMaxMarkRangeLength {
|
||||
return false
|
||||
}
|
||||
let text = (composingBuffer as NSString).substring(with: markedRange)
|
||||
let (exactBegin, _) = (composingBuffer as NSString).characterIndex(from: markedRange.location)
|
||||
let (exactEnd, _) = (composingBuffer as NSString).characterIndex(from: markedRange.location + markedRange.length)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
return LanguageModelManager.checkIfExist(userPhrase: text, key: joined) == false
|
||||
}
|
||||
|
||||
@objc var userPhrase: String {
|
||||
|
|
|
@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (void)loadUserPhraseReplacement;
|
||||
+ (void)setupDataModelValueConverter;
|
||||
+ (BOOL)checkIfUserLanguageModelFilesExist;
|
||||
|
||||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:));
|
||||
+ (BOOL)writeUserPhrase:(NSString *)userPhrase;
|
||||
|
||||
@property (class, readonly, nonatomic) NSString *dataFolderPath;
|
||||
|
|
|
@ -193,6 +193,19 @@ static void LTLoadAssociatedPhrases(McBopomofoLM &lm)
|
|||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:))
|
||||
{
|
||||
string unigramKey = string(key.UTF8String);
|
||||
vector<Unigram> unigrams = gLanguageModelMcBopomofo.unigramsForKey(unigramKey);
|
||||
string userPhraseString = string(userPhrase.UTF8String);
|
||||
for (auto unigram: unigrams) {
|
||||
if (unigram.keyValue.value == userPhraseString) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL)writeUserPhrase:(NSString *)userPhrase
|
||||
{
|
||||
if (![self checkIfUserLanguageModelFilesExist]) {
|
||||
|
|
|
@ -90,3 +90,6 @@
|
|||
"Cursor is after \"%@\"." = "Cursor is after \"%@\".";
|
||||
|
||||
"Cursor is between \"%@\" and \"%@\"." = "Cursor is between \"%@\" and \"%@\".";
|
||||
|
||||
"You are now selecting \"%@\". The phrase already exists." = "You are now selecting \"%@\". The phrase already exists.";
|
||||
|
||||
|
|
|
@ -47,11 +47,11 @@
|
|||
|
||||
"Use Half-Width Punctuations" = "使用半型標點符號";
|
||||
|
||||
"You are now selecting \"%@\". You can add a phrase with two or more characters." = "您目前選擇了 \"%@\"。請選擇兩個字以上,才能加入使用者詞彙。";
|
||||
"You are now selecting \"%@\". You can add a phrase with two or more characters." = "您目前選擇了「%@」。請選擇兩個字以上,才能加入使用者詞彙。";
|
||||
|
||||
"You are now selecting \"%@\". Press enter to add a new phrase." = "您目前選擇了 \"%@\"。按下 Enter 就可以加入到使用者詞彙中。";
|
||||
"You are now selecting \"%@\". Press enter to add a new phrase." = "您目前選擇了「%@」。按下 Enter 就可以加入到使用者詞彙中。";
|
||||
|
||||
"You are now selecting \"%@\". A phrase cannot be longer than %d characters." = "您目前選擇了 \"%@\"。自訂詞彙不能超過 %d 個字元。";
|
||||
"You are now selecting \"%@\". A phrase cannot be longer than %d characters." = "您目前選擇了「%@」。自訂詞彙不能超過 %d 個字元。";
|
||||
|
||||
"Chinese conversion on" = "已經切換到簡體中文模式";
|
||||
|
||||
|
@ -90,3 +90,5 @@
|
|||
"Cursor is after \"%@\"." = "游標正在「%@」後方";
|
||||
|
||||
"Cursor is between \"%@\" and \"%@\"." = "游標正在「%@」與「%@」之間";
|
||||
|
||||
"You are now selecting \"%@\". The phrase already exists." = "您目前選擇了「%@」,這個詞彙已經存在了";
|
||||
|
|
Loading…
Reference in New Issue