Esempio n. 1
0
        /// <summary>
        /// This function checks if all language keys in the project files
        /// are available in the language XML file.
        /// </summary>
        /// <param name="strProjectPath">Path to the project files with the language keys</param>
        public void CheckLanguageKeysOfProject(string strProjectPath)
        {
            if (!InitFlag)
            {
                return;
            }

            try
            {
                // Get all language keys in the project files
                if (_checkLanguageKeysInProjectFiles == null)
                {
                    _checkLanguageKeysInProjectFiles = new GetLanguageKeysInProjectFiles(strProjectPath);
                }

                // Get all available languages in the language XML file
                var availableLanguages = GetAvailableLanguages();

                // Loop through the languages and search for the language keys in the language XML file.
                foreach (var languageName in availableLanguages)
                {
                    foreach (var keyName in _checkLanguageKeysInProjectFiles.ListOfLanguageKeysAndProjectFileName.Keys)
                    {
                        // Try to get the language key value from the language file and if the return value is invalid
                        // add it to the invalid language key list.
                        if (GetLanguageTextByXPath(keyName, languageName) == InvalidLanguageKeyReturnValue)
                        {
                            InvalidLanguageKeysOfProject.Add(string.Format(@"{0,-15}: {1}", languageName, keyName + " (File: " + _checkLanguageKeysInProjectFiles.ListOfLanguageKeysAndProjectFileName[keyName]) + ")");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LastException = ex;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This function checks if all language keys in the XML language file
        /// are used in the project files.
        /// </summary>
        /// <param name="strProjectPath">Path to the project files with the used language keys</param>
        public void CheckLanguageKeysOfXml(string strProjectPath)
        {
            if (!InitFlag)
            {
                return;
            }

            try
            {
                // Flag if a XML language key is used or not
                var bXmlKeyUsed = false;

                // Get all language keys in the project files
                if (_checkLanguageKeysInProjectFiles == null)
                {
                    _checkLanguageKeysInProjectFiles = new GetLanguageKeysInProjectFiles(strProjectPath);
                }

                // Get all language keys in the project files
                if (_checkLanguageKeysInXmlFile == null)
                {
                    _checkLanguageKeysInXmlFile = new GetLanguageKeysInLanguageXml(_xmlDocument);
                }

                // Get all available languages in the language XML file
                var availableLanguages = GetAvailableLanguages();

                foreach (var keyNameXml in _checkLanguageKeysInXmlFile.ListOfLanguageKeys)
                {
                    foreach (var keyNameProject in _checkLanguageKeysInProjectFiles.ListOfLanguageKeysAndProjectFileName.Keys)
                    {
                        // Loop through the languages and search for the language keys in the language XML file.
                        foreach (var languageName in availableLanguages)
                        {
                            // Check for single line keys
                            if (keyNameXml == "/Language/" + languageName + keyNameProject)
                            {
                                bXmlKeyUsed = true;
                            }
                            else
                            {
                                // Check for multiline keys
                                // Remove last XML part
                                var xmlSplitParts   = keyNameXml.Split('/');
                                var xmlKeyNameLines = @"";

                                for (var i = 0; i < xmlSplitParts.Length - 1; i++)
                                {
                                    if (xmlSplitParts[i] == @"")
                                    {
                                        continue;
                                    }

                                    xmlKeyNameLines += "/";
                                    xmlKeyNameLines += xmlSplitParts[i];
                                }

                                xmlKeyNameLines += "/*";

                                if (xmlKeyNameLines == "/Language/" + languageName + keyNameProject)
                                {
                                    bXmlKeyUsed = true;
                                }
                            }
                        }
                    }
                    if (bXmlKeyUsed == false)
                    {
                        // Split XPath in the language and language key
                        // Remove /Language/ part
                        var keyName = keyNameXml.Remove(0, 1);
                        keyName = keyName.Remove(0, keyName.IndexOf('/') + 1);
                        var languageName = keyName.Substring(0, keyName.IndexOf('/') + 1);
                        languageName = languageName.Remove(keyName.IndexOf('/'), 1);
                        keyName      = keyName.Substring(keyName.IndexOf('/'));
                        InvalidLanguageKeysOfXml.Add($"{languageName,-15}: {keyName}");
                    }

                    bXmlKeyUsed = false;
                }
            }
            catch (Exception ex)
            {
                LastException = ex;
            }
        }