Example #1
0
        static SharedTableData.SharedTableEntry GetOrCreateEntryFromTranslationUnit(SharedTableData sharedTableData, ITranslationUnit unit)
        {
            // Does it contain an id?
            long   keyId = SharedTableData.EmptyId;
            string name  = null;

            if (!string.IsNullOrEmpty(unit.Id))
            {
                if (long.TryParse(unit.Id, out keyId))
                {
                    var entry = sharedTableData.GetEntry(keyId);
                    if (entry != null)
                    {
                        return(entry);
                    }
                }
                else
                {
                    // Is the Id a name?
                    var entry = sharedTableData.GetEntry(unit.Id);
                    if (entry != null)
                    {
                        return(entry);
                    }
                    name = unit.Id;
                }
            }

            // Use the name
            if (!string.IsNullOrEmpty(unit.Name))
            {
                var entry = sharedTableData.GetEntry(unit.Name);
                if (entry != null)
                {
                    return(entry);
                }
                name = unit.Name;
            }

            // Create a new entry
            if (keyId != SharedTableData.EmptyId)
            {
                return(sharedTableData.AddKey(name, keyId));
            }
            if (!string.IsNullOrEmpty(name))
            {
                return(sharedTableData.AddKey(name));
            }
            return(sharedTableData.AddKey());
        }
Example #2
0
        public void AddEntry_UsesExistingSharedTableId_UsingKeyName()
        {
            const string entryName = "My Test Entry";

            // Add several entries including the one we care about
            m_SharedTableData.AddKey("Some Value 1");
            m_SharedTableData.AddKey("Some Value 2");
            var sharedEntry = m_SharedTableData.AddKey(entryName);

            m_SharedTableData.AddKey("Some Value 3");
            m_SharedTableData.AddKey("Some Value 4");

            var newEntry = m_Table.AddEntry(entryName, "entry value");

            Assert.AreEqual(sharedEntry.Id, newEntry.Data.Id, "Expected the new entry to use the correct key id from the Shared Table Data.");
        }
Example #3
0
        public void Setup()
        {
            LocalizationSettingsHelper.SaveCurrentSettings();

            m_SharedStringTableData = ScriptableObject.CreateInstance <SharedTableData>();
            m_SharedStringTableData.TableCollectionName     = kStringTableCollectionName;
            m_SharedStringTableData.TableCollectionNameGuid = kStringTableNameGuid;
            m_SharedStringTableData.AddKey(kStringKeyName, kStringKeyId);

            m_SharedAssetTableData = ScriptableObject.CreateInstance <SharedTableData>();
            m_SharedAssetTableData.TableCollectionName     = kAssetTableCollectionName;
            m_SharedAssetTableData.TableCollectionNameGuid = kAssetTableNameGuid;

            m_Settings = LocalizationSettingsHelper.CreateEmpty();
            var stringDb = new LocalizedStringDatabase();

            m_Settings.SetStringDatabase(stringDb);
            var assetDb = new LocalizedAssetDatabase();

            m_Settings.SetAssetDatabase(assetDb);

            var rm = new ResourceManager();

            stringDb.SharedTableDataOperations[kStringTableNameGuid] = rm.CreateCompletedOperation(m_SharedStringTableData, null);
            assetDb.SharedTableDataOperations[kAssetTableNameGuid]   = rm.CreateCompletedOperation(m_SharedAssetTableData, null);

            LocalizationSettings.Instance = m_Settings;
        }
Example #4
0
        public void Init()
        {
            m_SharedTableData = ScriptableObject.CreateInstance <SharedTableData>();

            for (int i = 0; i < 100; ++i)
            {
                m_SharedTableData.AddKey("My Key " + i);
            }
        }
Example #5
0
        public void Setup()
        {
            m_SharedTableData = ScriptableObject.CreateInstance <SharedTableData>();
            var key = m_SharedTableData.AddKey();

            key.Metadata.AddMetadata(new Comment {
                CommentText = kCommentText
            });

            m_SharedTableDataSerializedObject = new SerializedObject(m_SharedTableData);
            m_SharedEntryMetadataProperty     = m_SharedTableDataSerializedObject.FindProperty(kMetadataPath);
            m_CommentProperty = m_SharedEntryMetadataProperty.FindPropertyRelative(kCommentPath);
        }
Example #6
0
        public SharedTableData.SharedTableEntry PullKey(string cellValue, string cellNote)
        {
            if (!string.IsNullOrEmpty(cellNote) && uint.TryParse(cellNote, out var keyId))
            {
                var entry = m_SharedTableData.GetEntry(keyId);
                if (entry != null)
                {
                    if (entry.Key != cellValue)
                    {
                        m_SharedTableData.RenameKey(entry.Key, cellValue);
                    }
                    return(entry);
                }
                else
                {
                    // Create a new entry with the id
                    return(m_SharedTableData.AddKey(cellValue, keyId));
                }
            }

            return(m_SharedTableData.GetEntry(cellValue) ?? m_SharedTableData.AddKey(cellValue));
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cellValue"></param>
        /// <param name="cellNote"></param>
        /// <returns></returns>
        public SharedTableData.SharedTableEntry PullKey(string cellValue, string cellNote)
        {
            if (!string.IsNullOrEmpty(cellNote) && long.TryParse(cellNote, out var keyId))
            {
                var entry = m_SharedTableData.GetEntry(keyId);
                if (entry != null)
                {
                    if (entry.Key != cellValue)
                    {
                        m_SharedTableData.RenameKey(entry.Key, cellValue);
                    }
                    return(entry);
                }


                // Debug.Log($"adding key {cellValue }");
                // Create a new entry with the id
                return(m_SharedTableData.AddKey(cellValue, keyId));
            }

            Debug.Log(m_SharedTableData.GetEntry(cellValue));
            return(m_SharedTableData.GetEntry(cellValue) ?? m_SharedTableData.AddKey(cellValue));
        }
Example #8
0
 public void AddAndVerifyKeyIsAdded(string keyName)
 {
     Assert.IsFalse(m_SharedTableData.Contains(keyName), "Expected the key to not already be in the shared table data.");
     Assert.IsNotNull(m_SharedTableData.AddKey(keyName), "Expected the key to added however it was not.");
     Assert.IsTrue(m_SharedTableData.Contains(keyName), "Expected the key to be contained in the  shared table data.");
 }