diff --git a/Source/Base.lproj/Localizable.strings b/Source/Base.lproj/Localizable.strings index 3f906806..6a30f895 100644 --- a/Source/Base.lproj/Localizable.strings +++ b/Source/Base.lproj/Localizable.strings @@ -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."; diff --git a/Source/InputState.swift b/Source/InputState.swift index 23f2f39c..61217c47 100644 --- a/Source/InputState.swift +++ b/Source/InputState.swift @@ -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..= 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.. 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]) { diff --git a/Source/en.lproj/Localizable.strings b/Source/en.lproj/Localizable.strings index 3f906806..acaee5b1 100644 --- a/Source/en.lproj/Localizable.strings +++ b/Source/en.lproj/Localizable.strings @@ -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."; + diff --git a/Source/zh-Hant.lproj/Localizable.strings b/Source/zh-Hant.lproj/Localizable.strings index 3bcd325e..36c4370c 100644 --- a/Source/zh-Hant.lproj/Localizable.strings +++ b/Source/zh-Hant.lproj/Localizable.strings @@ -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." = "您目前選擇了「%@」,這個詞彙已經存在了";