Exemple #1
0
        /// <summary>Deal with special Audio handling</summary>
        private void HandleAudioVariant()
        {
            VariantSubtag[] variantSubtags = VariantSubtags.ToArray();
            if (variantSubtags.Length == 1 && variantSubtags[0] == WellKnownSubtags.AudioPrivateUse)
            {
                m_ws.IsVoice         = true;
                m_scriptName.Enabled = false;
                string newScriptName = StandardSubtags.RegisteredScripts[WellKnownSubtags.AudioScript].Name;
                if (m_scriptNameString != newScriptName)
                {
                    if (m_scriptName.FindStringExact(newScriptName) < 0)
                    {
                        m_scriptName.Items.Add(WellKnownSubtags.AudioScript);
                    }
                    ScriptName = newScriptName;
                }
                m_variantAbbrev.Text    = "x-" + WellKnownSubtags.AudioPrivateUse;
                m_variantAbbrev.Enabled = false;
                m_scriptAbbrev.Text     = WellKnownSubtags.AudioScript;
            }
            else
            {
                //we are changing from Audio to something else
                if (m_scriptAbbrev.Text == WellKnownSubtags.AudioScript)
                {
                    m_scriptAbbrev.Text        = "";
                    ScriptName                 = "";
                    m_enableLangTagSideEffects = true;
                }

                m_ws.IsVoice = false;

                // Safest to set AFTER we turn off IsVoice, but BEFORE we change the script, to avoid
                // a tempoarty invalid state. But we can't, too bad, it's invalid until this line.
                m_ws.Variants.Clear();
                foreach (VariantSubtag variantSubtag in variantSubtags)
                {
                    m_ws.Variants.Add(variantSubtag);
                }

                m_scriptName.Enabled = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Check that the contents of the control are valid. If not, report the error
        /// to the user and return false. This should prevent the user from closing the
        /// containing form using OK, but not from cancelling.
        /// </summary>
        public bool CheckValid()
        {
            CheckDisposed();

            string caption = FwCoreDlgControls.kstidError;

            ScriptSubtag scriptSubtag = ScriptSubtag;

            // Can't allow a script name without an abbreviation.
            if (scriptSubtag == null && !string.IsNullOrEmpty(m_scriptName.Text.Trim()))
            {
                MessageBox.Show(FindForm(), FwCoreDlgControls.kstidMissingScrAbbr, caption);
                return(false);
            }
            if (scriptSubtag != null && scriptSubtag.IsPrivateUse)
            {
                if (StandardSubtags.RegisteredScripts.Contains(scriptSubtag.Code))
                {
                    MessageBox.Show(FindForm(), FwCoreDlgControls.kstidDupScrAbbr, caption);
                    return(false);
                }
                if (!IetfLanguageTag.IsValidScriptCode(scriptSubtag.Code))
                {
                    MessageBox.Show(FindForm(), FwCoreDlgControls.kstidInvalidScrAbbr, caption);
                    return(false);
                }
            }

            RegionSubtag regionSubtag = RegionSubtag;

            // Can't allow a country name without an abbreviation.
            if (regionSubtag == null && !string.IsNullOrEmpty(m_regionName.Text.Trim()))
            {
                MessageBox.Show(FindForm(), FwCoreDlgControls.kstidMissingRgnAbbr, caption);
                return(false);
            }
            if (regionSubtag != null && regionSubtag.IsPrivateUse)
            {
                if (StandardSubtags.RegisteredRegions.Contains(regionSubtag.Code))
                {
                    MessageBox.Show(FindForm(), FwCoreDlgControls.kstidDupRgnAbbr, caption);
                    return(false);
                }
                if (!IetfLanguageTag.IsValidRegionCode(regionSubtag.Code))
                {
                    MessageBox.Show(FindForm(), FwCoreDlgControls.kstidInvalidRgnAbbr, caption);
                    return(false);
                }
            }

            VariantSubtag[] variantSubtags = VariantSubtags.ToArray();
            // Can't allow a variant name without an abbreviation.
            if (string.IsNullOrEmpty(m_variantAbbrev.Text.Trim()) && !string.IsNullOrEmpty(m_variantName.Text.Trim()))
            {
                MessageBox.Show(FindForm(), FwCoreDlgControls.kstidMissingVarAbbr, caption);
                return(false);
            }

            if (variantSubtags.Length > 0)
            {
                foreach (VariantSubtag variantSubtag in variantSubtags)
                {
                    if (variantSubtag.IsPrivateUse)
                    {
                        if (StandardSubtags.RegisteredVariants.Contains(variantSubtag.Code))
                        {
                            MessageBox.Show(FindForm(), FwCoreDlgControls.kstidDupVarAbbr, caption);
                            return(false);
                        }
                        if (!IetfLanguageTag.IsValidPrivateUseCode(variantSubtag.Code))
                        {
                            MessageBox.Show(FindForm(), FwCoreDlgControls.kstidInvalidVarAbbr, caption);
                            return(false);
                        }
                    }
                }

                List <string> parts = variantSubtags.Select(v => v.Code).ToList();
                // If these subtags are private use, the first element of each must also be distinct.
                if (m_ws.Language.IsPrivateUse)
                {
                    parts.Add(m_ws.Language.Code.Split('-').First());
                }
                if (scriptSubtag != null && scriptSubtag.IsPrivateUse)
                {
                    parts.Add(scriptSubtag.Code.Split('-').First());
                }
                if (regionSubtag != null && regionSubtag.IsPrivateUse)
                {
                    parts.Add(regionSubtag.Code.Split('-').First());
                }
                var uniqueParts = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                foreach (string part in parts)
                {
                    if (uniqueParts.Contains(part))
                    {
                        MessageBox.Show(FindForm(), String.Format(FwCoreDlgControls.kstidDuplicateParts, part), caption);
                        return(false);
                    }
                    uniqueParts.Add(part);
                }
            }

            return(true);
        }