public LanguageController(ICurrentLanguage currentLanguage, ILanguageSource languageSource) { _currentLanguage = currentLanguage; _languageSource = languageSource; Contract.Ensures(_currentLanguage != null); Contract.Ensures(_languageSource != null); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { var source = languageSource.GetSource(); throw new MustBeImplementedException(); //return null; }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { var source = languageSource.GetSource(); throw new MustBeImplementedException(); //return null; }
public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { if (string.Equals(resourceName, "DynamicResource")) { return($"Dynamic resource in '{cultureInfo}'"); } return(base.GetString(languageSource, resourceName, cultureInfo)); }
/// <summary> /// Registers the language source. /// </summary> /// <param name="languageSource">The language source.</param> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c> or whitespace.</exception> public void RegisterLanguageSource(ILanguageSource languageSource) { Argument.IsNotNull("languageSource", languageSource); lock (_languageSources) { _languageSources.Insert(0, languageSource); } }
protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { if (string.Equals(resourceName, "DynamicResource")) { return string.Format("Dynamic resource in '{0}'", cultureInfo); } return base.GetString(languageSource, resourceName, cultureInfo); }
protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { if (string.Equals(resourceName, "DynamicResource")) { return(string.Format("Dynamic resource in '{0}'", cultureInfo)); } return(base.GetString(languageSource, resourceName, cultureInfo)); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected virtual string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); #if NETFX_CORE return(resourceLoader.GetString(resourceName)); #else return(resourceLoader.GetString(resourceName, cultureInfo)); #endif }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="resourceName" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="cultureInfo" /> is <c>null</c>.</exception> public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { Argument.IsNotNull("languageSource", languageSource); Argument.IsNotNullOrWhitespace("resourceName", resourceName); Argument.IsNotNull("cultureInfo", cultureInfo); var source = languageSource.GetSource(); throw new MustBeImplementedException(); //return null; }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="resourceName" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="cultureInfo" /> is <c>null</c>.</exception> public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { Argument.IsNotNull("languageSource", languageSource); Argument.IsNotNullOrWhitespace("resourceName", resourceName); Argument.IsNotNull("cultureInfo", cultureInfo); var source = languageSource.GetSource(); throw new MustBeImplementedException(); //return null; }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); if (resourceLoader != null) { #if NETFX_CORE return resourceLoader.GetString(resourceName); #else return resourceLoader.GetString(resourceName, cultureInfo); #endif } return null; }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); if (resourceLoader != null) { #if NETFX_CORE return(resourceLoader.GetString(resourceName)); #else return(resourceLoader.GetString(resourceName, cultureInfo)); #endif } return(null); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { string value = null; var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); if (resourceLoader != null) { #if NETFX_CORE var resourceContainer = GetResourceContainer(source); // Try the language specific first var neutralSource = string.Format("{0}", resourceContainer); var languageSpecificSource = string.Format("{0}.{1}", resourceContainer, cultureInfo.Name); var currentResourceManager = Windows.ApplicationModel.Resources.Core.ResourceManager.Current; var finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps where resourceMap.Value.GetSubtree(languageSpecificSource) != null select resourceMap.Value.GetSubtree(languageSpecificSource)).FirstOrDefault(); if (finalResourceMap == null) { finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps where resourceMap.Value.GetSubtree(neutralSource) != null select resourceMap.Value.GetSubtree(neutralSource)).FirstOrDefault(); } if (finalResourceMap != null) { var resourceContext = ResourceContext.GetForViewIndependentUse(); resourceContext.Languages = new[] { cultureInfo.Name }; var resourceCandidate = finalResourceMap.GetValue(resourceName, resourceContext); if (resourceCandidate != null) { value = resourceCandidate.ValueAsString; } } #else value = resourceLoader.GetString(resourceName, cultureInfo); #endif } return value; }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { string value = null; var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); if (resourceLoader != null) { #if NETFX_CORE var resourceContainer = GetResourceContainer(source); // Try the language specific first var neutralSource = string.Format("{0}", resourceContainer); var languageSpecificSource = string.Format("{0}.{1}", resourceContainer, cultureInfo.Name); var currentResourceManager = Windows.ApplicationModel.Resources.Core.ResourceManager.Current; var finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps where resourceMap.Value.GetSubtree(languageSpecificSource) != null select resourceMap.Value.GetSubtree(languageSpecificSource)).FirstOrDefault(); if (finalResourceMap == null) { finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps where resourceMap.Value.GetSubtree(neutralSource) != null select resourceMap.Value.GetSubtree(neutralSource)).FirstOrDefault(); } if (finalResourceMap != null) { var resourceContext = ResourceContext.GetForViewIndependentUse(); resourceContext.Languages = new[] { cultureInfo.Name }; var resourceCandidate = finalResourceMap.GetValue(resourceName, resourceContext); if (resourceCandidate != null) { value = resourceCandidate.ValueAsString; } } #else value = resourceLoader.GetString(resourceName, cultureInfo); #endif } return(value); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { //var source = languageSource.GetSource(); //var stringsXml = string.Format("res/values-{0}/strings.xml", cultureInfo.TwoLetterISOLanguageName.ToLower()); //var xpath = string.Format("/resources/string[@name='{0}']", resourceName); //var stringsXmlDocument = XDocument.Load(stringsXml); //var element = stringsXmlDocument.XPathSelectElement(xpath); //return element.Value; var context = Android.ContextHelper.CurrentContext; var packageName = context.PackageName; var id = context.Resources.GetIdentifier(resourceName, "string", packageName); //var id = Resources.System.GetIdentifier(resourceName, "string", packageName); return context.GetString(id); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { //var source = languageSource.GetSource(); //var stringsXml = string.Format("res/values-{0}/strings.xml", cultureInfo.TwoLetterISOLanguageName.ToLower()); //var xpath = string.Format("/resources/string[@name='{0}']", resourceName); //var stringsXmlDocument = XDocument.Load(stringsXml); //var element = stringsXmlDocument.XPathSelectElement(xpath); //return element.Value; var context = Android.ContextHelper.CurrentContext; var packageName = context.PackageName; var id = context.Resources.GetIdentifier(resourceName, "string", packageName); //var id = Resources.System.GetIdentifier(resourceName, "string", packageName); return(context.GetString(id)); }
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected override void PreloadLanguageSource(ILanguageSource languageSource) { GetResourceManager(languageSource.GetSource()); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="resourceName" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="cultureInfo" /> is <c>null</c>.</exception> public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { Argument.IsNotNull("languageSource", languageSource); Argument.IsNotNullOrWhitespace("resourceName", resourceName); Argument.IsNotNull("cultureInfo", cultureInfo); string value = null; var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); if (resourceLoader != null) { #if NETFX_CORE var resourceContainer = GetResourceContainer(source); // Try the language specific first var neutralSource = string.Format("{0}", resourceContainer); var cultureName = cultureInfo.Name; var languageSpecificSource = string.Format("{0}.{1}", resourceContainer, cultureName); var currentResourceManager = Windows.ApplicationModel.Resources.Core.ResourceManager.Current; var finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps let rm = resourceMap.Value.GetSubtree(languageSpecificSource) where rm != null select rm).FirstOrDefault(); if ((finalResourceMap == null) && !cultureInfo.IsNeutralCulture) { cultureName = cultureInfo.Parent.Name; languageSpecificSource = string.Format("{0}.{1}", resourceContainer, cultureName); finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps let rm = resourceMap.Value.GetSubtree(languageSpecificSource) where rm != null select rm).FirstOrDefault(); } if (finalResourceMap == null) { finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps let rm = resourceMap.Value.GetSubtree(neutralSource) where rm != null select rm).FirstOrDefault(); } if (finalResourceMap != null) { var resourceContext = ResourceContext.GetForViewIndependentUse(); resourceContext.Languages = new[] { cultureName }; var resourceCandidate = finalResourceMap.GetValue(resourceName, resourceContext); if (resourceCandidate != null) { value = resourceCandidate.ValueAsString; } } #else value = resourceLoader.GetString(resourceName, cultureInfo); #endif } return(value); }
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected override void PreloadLanguageSource(ILanguageSource languageSource) { GetResourceManager(languageSource.GetSource()); }
public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { return _values[resourceName]; }
/// <summary> /// Registers the language source. /// </summary> /// <param name="languageSource">The language source.</param> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c> or whitespace.</exception> public void RegisterLanguageSource(ILanguageSource languageSource) { Argument.IsNotNull(() => languageSource); _languageSources.Insert(0, languageSource); }
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected override void PreloadLanguageSource(ILanguageSource languageSource) { // TODO: cache parsed string xmls? }
public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { return(_values[resourceName]); }
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected abstract void PreloadLanguageSource(ILanguageSource languageSource);
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected abstract string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo);
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected override void PreloadLanguageSource(ILanguageSource languageSource) { // Not required }
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected override void PreloadLanguageSource(ILanguageSource languageSource) { // Not required }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> protected virtual string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); #if NETFX_CORE return resourceLoader.GetString(resourceName); #else return resourceLoader.GetString(resourceName, cultureInfo); #endif }
/// <summary> /// Registers the language source. /// </summary> /// <param name="languageSource">The language source.</param> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c> or whitespace.</exception> public void RegisterLanguageSource(ILanguageSource languageSource) { Argument.IsNotNull("languageSource", languageSource); _languageSources.Insert(0, languageSource); }
/// <summary> /// Preloads the language sources to provide optimal performance. /// </summary> /// <param name="languageSource">The language source.</param> protected override void PreloadLanguageSource(ILanguageSource languageSource) { // TODO: cache parsed string xmls? }
void OnGUI_Source() { GUILayout.BeginHorizontal(); ILanguageSource currentSource = mLocalize.Source; if (currentSource == null) { LanguageSourceData source = LocalizationManager.GetSourceContaining(mLocalize.Term); currentSource = source == null ? null : source.owner; } if (GUILayout.Button("Open Source", EditorStyles.toolbarButton, GUILayout.Width(100))) { Selection.activeObject = currentSource as UnityEngine.Object; string sTerm, sSecondary; mLocalize.GetFinalTerms(out sTerm, out sSecondary); if (GUI_SelectedTerm == 1) { sTerm = sSecondary; } LocalizationEditor.mKeyToExplore = sTerm; } GUILayout.Space(2); GUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginChangeCheck(); if (mLocalize.Source == null) { GUI.contentColor = Color.Lerp(Color.gray, Color.yellow, 0.1f); } Object obj = EditorGUILayout.ObjectField(currentSource as Object, typeof(Object), true); GUI.contentColor = Color.white; if (EditorGUI.EndChangeCheck()) { ILanguageSource NewSource = obj as ILanguageSource; if (NewSource == null && (obj as GameObject != null)) { NewSource = (obj as GameObject).GetComponent <LanguageSource>(); } mLocalize.Source = NewSource; string sTerm, sSecondary; mLocalize.GetFinalTerms(out sTerm, out sSecondary); if (GUI_SelectedTerm == 1) { sTerm = sSecondary; } UpdateTermsList(sTerm); } if (GUILayout.Button(new GUIContent("Detect", "Finds the LanguageSource containing the selected term, the term list will now only show terms inside that source."), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { string sTerm, sSecondary; mLocalize.GetFinalTerms(out sTerm, out sSecondary); if (GUI_SelectedTerm == 1) { sTerm = sSecondary; } var data = LocalizationManager.GetSourceContaining(sTerm, false); mLocalize.Source = data == null ? null : data.owner; mTermsArray = null; } GUILayout.EndHorizontal(); GUILayout.EndHorizontal(); }
/// <summary> /// Gets the string from the specified resource file with the current culture. /// </summary> /// <param name="languageSource">The language source.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns>The string or <c>null</c> if the string cannot be found.</returns> /// <exception cref="ArgumentNullException">The <paramref name="languageSource" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="resourceName" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="cultureInfo" /> is <c>null</c>.</exception> public override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo) { Argument.IsNotNull("languageSource", languageSource); Argument.IsNotNullOrWhitespace("resourceName", resourceName); Argument.IsNotNull("cultureInfo", cultureInfo); string value = null; var source = languageSource.GetSource(); var resourceLoader = GetResourceManager(source); if (resourceLoader != null) { #if NETFX_CORE var resourceContainer = GetResourceContainer(source); // Try the language specific first var neutralSource = string.Format("{0}", resourceContainer); var cultureName = cultureInfo.Name; var languageSpecificSource = string.Format("{0}.{1}", resourceContainer, cultureName); var currentResourceManager = Windows.ApplicationModel.Resources.Core.ResourceManager.Current; var finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps let rm = resourceMap.Value.GetSubtree(languageSpecificSource) where rm != null select rm).FirstOrDefault(); if ((finalResourceMap == null) && !cultureInfo.IsNeutralCulture) { cultureName = cultureInfo.Parent.Name; languageSpecificSource = string.Format("{0}.{1}", resourceContainer, cultureName); finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps let rm = resourceMap.Value.GetSubtree(languageSpecificSource) where rm != null select rm).FirstOrDefault(); } if (finalResourceMap == null) { finalResourceMap = (from resourceMap in currentResourceManager.AllResourceMaps let rm = resourceMap.Value.GetSubtree(neutralSource) where rm != null select rm).FirstOrDefault(); } if (finalResourceMap != null) { var resourceContext = ResourceContext.GetForViewIndependentUse(); resourceContext.Languages = new[] { cultureName }; var resourceCandidate = finalResourceMap.GetValue(resourceName, resourceContext); if (resourceCandidate != null) { value = resourceCandidate.ValueAsString; } } #else value = resourceLoader.GetString(resourceName, cultureInfo); #endif } return value; }