static void WriteLocalizedValue(string valueName, StreamWriter stream, Locale locale, LocalizedString localizedString, PlistDocument plistDocument)
        {
            if (localizedString.IsEmpty)
            {
                return;
            }

            var tableCollection = LocalizationEditorSettings.GetStringTableCollection(localizedString.TableReference);
            var table           = tableCollection?.GetTable(locale.Identifier) as StringTable;
            var entry           = table?.GetEntryFromReference(localizedString.TableEntryReference);

            if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizedValue))
            {
                // Use fallback?
                var fallBack = FallbackLocaleHelper.GetLocaleFallback(locale);
                if (fallBack != null)
                {
                    WriteLocalizedValue(valueName, stream, fallBack, localizedString, plistDocument);
                    return;
                }

                Debug.LogWarning($"{valueName}: Could not find a localized value for {locale} from {localizedString}");
                return;
            }

            Debug.Assert(!entry.IsSmart, $"Localized App Values ({valueName}) do not support Smart Strings - {localizedString}");
            stream.WriteLine($"\"{valueName}\" = \"{entry.LocalizedValue}\";");

            plistDocument.root.SetString(valueName, string.Empty);
        }
Exemplo n.º 2
0
        static void GenerateLocalizedXmlFile(string valueName, string filePath, Locale locale, AppInfo appinfo)
        {
            var localizedString = appinfo.DisplayName;

            if (localizedString.IsEmpty)
            {
                return;
            }

            var tableCollection = LocalizationEditorSettings.GetStringTableCollection(localizedString.TableReference);
            var table           = tableCollection?.GetTable(locale.Identifier) as StringTable;
            var entry           = table?.GetEntryFromReference(localizedString.TableEntryReference);

            if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizedValue))
            {
                // Use fallback?
                var fallBack = FallbackLocaleHelper.GetLocaleFallback(locale);
                if (fallBack != null)
                {
                    GenerateLocalizedXmlFile(valueName, filePath, fallBack, appinfo);
                    return;
                }

                Debug.LogWarning($"{valueName}: Could not find a localized value for {locale} from {localizedString}");
                return;
            }
            Debug.Assert(!entry.IsSmart, $"Localized App Values ({valueName}) do not support Smart Strings - {localizedString}");
            Debug.Assert(!entry.LocalizedValue.Contains("'"), $"Localized App Value ({valueName}) does not support Single Quote. \nEntry contains invalid character: {localizedString}\n{entry.LocalizedValue}");

            using (var stream = new StreamWriter(filePath, false, Encoding.UTF8))
            {
                stream.WriteLine(
                    $@"<?xml version=""1.0"" encoding=""utf-8""?>" +
                    "<!--" +
                    "\n" +
                    $"\t{k_InfoFile}\n" +
                    $"\tThis file was auto-generated by {LocalizationPackageInfo.name}\n" +
                    $"\tVersion {LocalizationPackageInfo.version}\n" +
                    $"\tChanges to this file may cause incorrect behavior and will be lost if the project is rebuilt.\n" +
                    $"-->" +
                    "\n" +
                    $@"<resources>
                       <string name=""app_name""> {entry.LocalizedValue} </string>
                       </resources>");
            }
        }
Exemplo n.º 3
0
        static void GenerateLocalizedIcon(string filePath, Locale locale, LocalizedTexture localizedTexture)
        {
            if (localizedTexture.IsEmpty)
            {
                return;
            }

            var tableCollection = LocalizationEditorSettings.GetAssetTableCollection(localizedTexture.TableReference);
            var table           = tableCollection?.GetTable(locale.Identifier) as AssetTable;
            var entry           = table?.GetEntryFromReference(localizedTexture.TableEntryReference);

            if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizedValue))
            {
                var fallBack = FallbackLocaleHelper.GetLocaleFallback(locale);
                if (fallBack != null)
                {
                    GenerateLocalizedIcon(filePath, fallBack, localizedTexture);
                    return;
                }

                Debug.LogWarning($"Could not find a localized Icons for {locale} from {localizedTexture}");
                return;
            }
            var iconPath = AssetDatabase.GUIDToAssetPath(entry.Guid);

            if (string.IsNullOrEmpty(iconPath))
            {
                return;
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var texture = AssetDatabase.LoadAssetAtPath(iconPath, typeof(Texture2D)) as Texture2D;

            byte[] bytes = texture.EncodeToPNG();

            //Saving the Icon as ".png" file to gradle res folder
            File.WriteAllBytes(filePath, bytes);
        }