public void LoadLocalizedText(string fileName) { LocalizedDictionary dictionary = new LocalizedDictionary(); string filePath = Path.Combine(Application.streamingAssetsPath, fileName); if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); LocalizationData loadedData = JsonUtility.FromJson <LocalizationData> (dataAsJson); for (int i = 0; i < loadedData.items.Length; i++) { dictionary.localizedText.Add(loadedData.items [i].unloc, loadedData.items [i].loc); } if (dictionary.localizedText.ContainsKey("LOC_NAME")) { dictionary.localizedName = dictionary.localizedText ["LOC_NAME"]; } dictionaries.Add(dictionary); Debug.Log("Loaded localization data for " + dictionary.localizedName + ", dictionary contains: " + dictionary.localizedText.Count + " entries"); } else { Debug.Assert(false, "Cannot find file!"); } }
public IEnumerable <RecognizeEntity <string> > RecognizeLocalizedChoices(IMessageActivity message, string choicesKey, ResourceManager resourceManager, IPromptRecognizeChoicesOptions options = null) { var locale = message?.Locale ?? string.Empty; LocalizedDictionary <ChoicesDictionary> cachedLocalizedChoices; if (!choicesCache.TryGetValue(choicesKey, out cachedLocalizedChoices)) { var localizedChoices = new LocalizedDictionary <ChoicesDictionary>(); cachedLocalizedChoices = choicesCache.GetOrAdd(choicesKey, localizedChoices); } ChoicesDictionary cachedChoices; if (!cachedLocalizedChoices.TryGetValue(locale, out cachedChoices)) { var choicesArray = GetLocalizedResource(choicesKey, locale, resourceManager).Split('|'); var choices = ConvertToChoices(choicesArray); cachedChoices = cachedLocalizedChoices.GetOrAdd(locale, choices); } return(RecognizeChoices(message, cachedChoices, options)); }
public IEnumerable <RecognizeEntity <string> > RecognizeLocalizedRegExp(IMessageActivity message, string expressionKey, ResourceManager resourceManager) { var entities = new List <RecognizeEntity <string> >(); var locale = message?.Locale ?? string.Empty; var utterance = message?.Text?.Trim().ToLowerInvariant() ?? string.Empty; LocalizedDictionary <Regex> cachedLocalizedRegex; if (!expCache.TryGetValue(expressionKey, out cachedLocalizedRegex)) { var localizedRegex = new LocalizedDictionary <Regex>(); cachedLocalizedRegex = expCache.GetOrAdd(expressionKey, localizedRegex); } Regex cachedRegex; if (!cachedLocalizedRegex.TryGetValue(locale, out cachedRegex)) { var expression = GetLocalizedResource(expressionKey, locale, resourceManager); var regex = new Regex(expression, RegexOptions.IgnoreCase | RegexOptions.Compiled); cachedRegex = cachedLocalizedRegex.GetOrAdd(locale, regex); } foreach (Match match in cachedRegex.Matches(utterance)) { if (match.Success) { entities.Add(new RecognizeEntity <string> { Entity = match.Value, Score = CalculateScore(utterance, match.Value) }); } } return(entities); }