Пример #1
0
        void ResolveTableCollection()
        {
            m_PossibleTableCollection.Clear();
            m_Collection = LocalizationEditorSettings.GetCollectionFromTable(m_TargetTable);

            if (m_TargetTable.SharedData == null)
            {
                return;
            }

            m_SharedTableDataSerializedObject = new SerializedObject(m_TargetTable.SharedData);
            m_TableCollectionName             = m_SharedTableDataSerializedObject.FindProperty("m_TableCollectionName");

            if (m_Collection != null)
            {
                m_CollectionButton = new GUIContent("Select Collection", EditorGUIUtility.ObjectContent(m_Collection, m_Collection.GetType()).image);
                return;
            }

            m_SharedTableDataCollection = LocalizationEditorSettings.GetCollectionForSharedTableData(m_TargetTable.SharedData);
            if (m_SharedTableDataCollection != null)
            {
                return;
            }

            LocalizationEditorSettings.FindLooseStringTablesUsingSharedTableData(m_TargetTable.SharedData, m_PossibleTableCollection);
        }
Пример #2
0
        static void ImportStringTable(MenuCommand command)
        {
            var table = command.context as StringTable;

            Assert.IsTrue(table != null, "Expected StringTable");

            var path = EditorUtility.OpenFilePanel($"Import CSV into {table.TableData}({table.LocaleIdentifier})", PreviousDirectory, "csv");

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

            EditorPrefs.SetString(kPrefFile, path);

            var collection = LocalizationEditorSettings.GetCollectionFromTable(table) as StringTableCollection;

            if (collection == null)
            {
                Debug.LogError("String Table must belong to a StringTableCollection.");
                return;
            }

            var cellMappings = new CsvColumns[] { new KeyIdColumns(), new LocaleColumns {
                                                      LocaleIdentifier = table.LocaleIdentifier
                                                  } };

            using (var stream = new StreamReader(path))
            {
                var reporter = TaskReporter.CreateDefaultReporter();
                reporter.Start("Importing " + path, string.Empty);
                Csv.ImportInto(stream, collection, cellMappings, true, reporter);
            }
        }
Пример #3
0
        static StringTableCollection FindProjectCollection(IFile file)
        {
            // When exporting we use the ID for the file GUID.
            string path = AssetDatabase.GUIDToAssetPath(file.Id);

            var filePath = string.IsNullOrEmpty(path) ? file.Original : path;

            if (!string.IsNullOrEmpty(filePath))
            {
                var table = AssetDatabase.LoadAssetAtPath <StringTable>(filePath);
                if (table != null)
                {
                    return(LocalizationEditorSettings.GetCollectionFromTable(table) as StringTableCollection);
                }
            }

            return(null);
        }
Пример #4
0
        static void ExportTable(StringTable table, bool includeComments)
        {
            var collection = LocalizationEditorSettings.GetCollectionFromTable(table) as StringTableCollection;

            if (collection == null)
            {
                Debug.LogError("String Table must belong to a StringTableCollection.");
                return;
            }

            var cellMappings = new CsvColumns[] { new KeyIdColumns {
                                                      IncludeSharedComments = includeComments
                                                  }, new LocaleColumns {
                                                      LocaleIdentifier = table.LocaleIdentifier, IncludeComments = includeComments
                                                  } };

            Export(cellMappings, collection);
        }
        public void SetSelection(LocalizationTable table)
        {
            SelectedTableIndexes.Clear();
            var collection = LocalizationEditorSettings.GetCollectionFromTable(table);

            var hashSet = new HashSet <int>();

            for (int i = 0; i < collection.Tables.Count; ++i)
            {
                if (collection.Tables[i].asset == table)
                {
                    hashSet.Add(i);
                    break;
                }
            }

            SelectedTableIndexes[collection] = hashSet;
            Initialize(false);
        }
Пример #6
0
        /// <summary>
        /// Import an XLIFF document into the target table, ignoring <see cref="IXliffDocument.TargetLanguage"/>.
        /// </summary>
        /// <param name="document">The XLIFF document to import.</param>
        /// <param name="target">The target table that will be populated with the translated values.</param>
        /// <param name="importNotesBehavior">How should the notes be imported?</param>
        /// <param name="reporter">Optional reporter which can report the current progress.</param>
        public static void ImportDocumentIntoTable(IXliffDocument document, StringTable target, ImportNotesBehavior importNotesBehavior = ImportNotesBehavior.Replace, ITaskReporter reporter = null)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            EditorUtility.SetDirty(target);

            float progress = reporter == null ? 0 : reporter.CurrentProgress + 0.1f;

            reporter?.ReportProgress("Importing XLIFF into table", progress);

            float progressStep = document.FileCount / (1.0f - progress);

            var options = new ImportOptions {
                UpdateSourceTable = false, ImportNotes = importNotesBehavior
            };

            for (int i = 0; i < document.FileCount; ++i)
            {
                var f = document.GetFile(i);
                progress += progressStep;
                reporter?.ReportProgress($"Importing({i + 1}/{document.FileCount}) {f.Id}", progress);
                ImportIntoTables(f, null, target, options);
            }

            var collection = LocalizationEditorSettings.GetCollectionFromTable(target);

            if (collection != null)
            {
                LocalizationEditorSettings.EditorEvents.RaiseCollectionModified(document, collection);
            }

            reporter?.Completed("Finished importing XLIFF");
        }