WitTexts.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. using UnityEngine;
  9. namespace Meta.WitAi
  10. {
  11. public static class WitTexts
  12. {
  13. // Localized text
  14. public static WitText Texts;
  15. [System.Serializable]
  16. public struct WitText
  17. {
  18. [Header("Shared Settings Texts")]
  19. public string LanguageID;
  20. public string WitAppsUrl;
  21. public string WitAppSettingsEndpoint;
  22. public string WitAppUnderstandingEndpoint;
  23. public string WitOpenButtonLabel;
  24. public string WitDocsTitle;
  25. public string WitDocsUrl;
  26. public string VLogLevelLabel;
  27. public string ConfigurationFileManagerLabel;
  28. public string ConfigurationFileNameLabel;
  29. public string ConfigurationSelectLabel;
  30. public string ConfigurationSelectMissingLabel;
  31. [Header("Setup Settings Texts")]
  32. public string SetupTitleLabel;
  33. public string SetupSubheaderLabel;
  34. public string SetupServerTokenLabel;
  35. public string SetupServerTokenVerifyLabel;
  36. public string SetupServerTokenVerifyWarning;
  37. public string SetupClientTokenWarningLabel;
  38. public string SetupSubmitButtonLabel;
  39. public string SetupSubmitFailLabel;
  40. [Header("Understanding Viewer Texts")]
  41. public string UnderstandingViewerLabel;
  42. public string UnderstandingViewerMissingConfigLabel;
  43. public string UnderstandingViewerMissingClientTokenLabel;
  44. public string UnderstandingViewerServicesLabel;
  45. public string UnderstandingViewerMissingServicesLabel;
  46. public string UnderstandingViewerSettingsButtonLabel;
  47. public string UnderstandingViewerUtteranceLabel;
  48. public string UnderstandingViewerPromptLabel;
  49. public string UnderstandingViewerSubmitButtonLabel;
  50. public string UnderstandingViewerActivateButtonLabel;
  51. public string UnderstandingViewerDeactivateButtonLabel;
  52. public string UnderstandingViewerAbortButtonLabel;
  53. public string UnderstandingViewerListeningLabel;
  54. public string UnderstandingViewerLoadingLabel;
  55. public string UnderstandingViewerSelectLabel;
  56. [Header("Settings Texts")]
  57. public string SettingsTitleLabel;
  58. public string SettingsServerTokenLabel;
  59. public string SettingsServerTokenTooltip;
  60. public string SettingsRelinkButtonLabel;
  61. public string SettingsAddButtonLabel;
  62. public string SettingsAddMainButtonLabel;
  63. [Header("Configuration Texts")]
  64. public string ConfigurationHeaderLabel;
  65. public string ConfigurationRefreshButtonLabel;
  66. public string ConfigurationRefreshingButtonLabel;
  67. public string ConfigurationServerTokenLabel;
  68. public string ConfigurationClientTokenLabel;
  69. public string ConfigurationRequestTimeoutLabel;
  70. [Header("Configuration Endpoint Texts")]
  71. public string ConfigurationEndpointTitleLabel;
  72. public string ConfigurationEndpointUriLabel;
  73. public string ConfigurationEndpointAuthLabel;
  74. public string ConfigurationEndpointPortLabel;
  75. public string ConfigurationEndpointApiLabel;
  76. public string ConfigurationEndpointSpeechLabel;
  77. public string ConfigurationEndpointMessageLabel;
  78. public string ConfigurationEndpointDictationLabel;
  79. public string ConfigurationEndpointSynthesizeLabel;
  80. public string ConfigurationEndpointComposerEventLabel;
  81. public string ConfigurationEndpointComposerConverseLabel;
  82. [Header("Configuration Application Texts")]
  83. public string ConfigurationApplicationTabLabel;
  84. public string ConfigurationApplicationMissingLabel;
  85. public string ConfigurationApplicationNameLabel;
  86. public string ConfigurationApplicationIdLabel;
  87. public string ConfigurationApplicationLanguageLabel;
  88. public string ConfigurationApplicationPrivateLabel;
  89. public string ConfigurationApplicationCreatedLabel;
  90. [Header("Configuration Application Training Texts")]
  91. public string ConfigurationApplicationTrainingStatus;
  92. public string ConfigurationApplicationTrainingLast;
  93. public string ConfigurationApplicationTrainingLastDuration;
  94. public string ConfigurationApplicationTrainingNext;
  95. [Header("Configuration Conduit Texts")]
  96. public string ConfigurationConduitMissingTokenLabel;
  97. [Header("Configuration Intent Texts")]
  98. public string ConfigurationIntentsTabLabel;
  99. public string ConfigurationIntentsMissingLabel;
  100. public string ConfigurationIntentsIdLabel;
  101. public string ConfigurationIntentsEntitiesLabel;
  102. [Header("Configuration Entity Texts")]
  103. public string ConfigurationEntitiesTabLabel;
  104. public string ConfigurationEntitiesMissingLabel;
  105. public string ConfigurationEntitiesIdLabel;
  106. public string ConfigurationEntitiesLookupsLabel;
  107. public string ConfigurationEntitiesRolesLabel;
  108. public string ConfigurationEntitiesKeywordsLabel;
  109. [Header("Configuration Trait Texts")]
  110. public string ConfigurationTraitsTabLabel;
  111. public string ConfigurationTraitsMissingLabel;
  112. public string ConfigurationTraitsIdLabel;
  113. public string ConfigurationTraitsValuesLabel;
  114. [Header("Configuration Voice Texts")]
  115. public string ConfigurationVoicesTabLabel;
  116. public string ConfigurationVoicesMissingLabel;
  117. [Header("Configuration Composer Texts")]
  118. public string ConfigurationComposerTabLabel;
  119. public string ConfigurationComposerMissingLabel;
  120. [Header("Tooltip Texts")]
  121. public string ShowTooltipsLabel;
  122. }
  123. // Wit
  124. public const string WitUrl = "https://wit.ai";
  125. // Endpoint
  126. public enum WitAppEndpointType
  127. {
  128. Settings,
  129. Understanding
  130. }
  131. // Title Contents
  132. public static Texture2D HeaderIcon;
  133. public static Texture2D TitleIcon;
  134. public static GUIContent SetupTitleContent;
  135. public static GUIContent UnderstandingTitleContent;
  136. public static GUIContent SettingsTitleContent;
  137. public static GUIContent SettingsServerTokenContent;
  138. public static GUIContent ConfigurationServerTokenContent;
  139. public static GUIContent ConfigurationClientTokenContent;
  140. public static GUIContent ConfigurationRequestTimeoutContent;
  141. // Init
  142. static WitTexts()
  143. {
  144. // Get text
  145. string languageID = "en-us";
  146. string textFilePath = $"witai_texts_{languageID}";
  147. TextAsset textAsset = Resources.Load<TextAsset>(textFilePath);
  148. if (textAsset == null)
  149. {
  150. VLog.E($"WitStyles - Add localization to Resources/{textFilePath}\nLanguage: {languageID}");
  151. return;
  152. }
  153. Texts = JsonUtility.FromJson<WitText>(textAsset.text);
  154. // Setup titles
  155. HeaderIcon = (Texture2D) Resources.Load("wit-ai-title");
  156. TitleIcon = (Texture2D) Resources.Load("witai");
  157. SetupTitleContent = new GUIContent(WitTexts.Texts.SetupTitleLabel, TitleIcon);
  158. SettingsTitleContent = new GUIContent(WitTexts.Texts.SettingsTitleLabel, TitleIcon);
  159. SettingsServerTokenContent = new GUIContent(WitTexts.Texts.SettingsServerTokenLabel, WitTexts.Texts.SettingsServerTokenTooltip);
  160. UnderstandingTitleContent = new GUIContent(WitTexts.Texts.UnderstandingViewerLabel, TitleIcon);
  161. ConfigurationServerTokenContent = new GUIContent(WitTexts.Texts.ConfigurationServerTokenLabel);
  162. ConfigurationClientTokenContent = new GUIContent(WitTexts.Texts.ConfigurationClientTokenLabel);
  163. ConfigurationRequestTimeoutContent = new GUIContent(WitTexts.Texts.ConfigurationRequestTimeoutLabel);
  164. }
  165. // Get urls
  166. public static string GetAppURL(string appId, WitAppEndpointType endpointType)
  167. {
  168. // Return apps url without id
  169. string url = WitUrl + Texts.WitAppsUrl;
  170. if (string.IsNullOrEmpty(appId))
  171. {
  172. return url;
  173. }
  174. // Determine endpoint
  175. string endpoint;
  176. switch (endpointType)
  177. {
  178. case WitAppEndpointType.Understanding:
  179. endpoint = Texts.WitAppUnderstandingEndpoint;
  180. break;
  181. case WitAppEndpointType.Settings:
  182. endpoint = Texts.WitAppSettingsEndpoint;
  183. break;
  184. default:
  185. endpoint = Texts.WitAppSettingsEndpoint;
  186. break;
  187. }
  188. // Ensure endpoint is set
  189. if (string.IsNullOrEmpty(endpoint))
  190. {
  191. return url;
  192. }
  193. // Replace app id key with desired app id
  194. endpoint = endpoint.Replace("[APP_ID]", appId);
  195. // Return full url
  196. return url + endpoint;
  197. }
  198. }
  199. }