GetValidLangTagForNewLang() public method

Returns an ISO 639 language tag that is guaranteed to be valid and unique for both the local and the global writing system store. NOTE: This method should only be used for writing systems that are custom (i.e. not defined in the current version of the ethnologue). The returned code will *not* have the 'x-' prefix denoting a user-defined writing system, but it will check that an existing user-defined writing system does not exist with the returned language tag. This method also does not worry about regions, variants, etc. as it's use is restricted to the language tag for a custom writing system.
public GetValidLangTagForNewLang ( string langName ) : string
langName string The full name of the language.
return string
        public void GetValidLangCodeForNewLang()
        {
            string storePath       = PrepareTempStore("Store");
            string globalStorePath = PrepareTempStore("GlobalStore");

            EnsureDirectoryIsEmpty(storePath);
            EnsureDirectoryIsEmpty(globalStorePath);

            var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
            var wsManager   = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath, globalStore), globalStore);

            Assert.AreEqual("qip", wsManager.GetValidLangTagForNewLang("Qipkey"));
            Assert.AreEqual("sn", wsManager.GetValidLangTagForNewLang("Sn"));
            Assert.AreEqual("eba", wsManager.GetValidLangTagForNewLang("\u00CBbashlish"));             // \u00CB == E with diacritic
            Assert.AreEqual("eee", wsManager.GetValidLangTagForNewLang("\u00CB\u00CB\u00CBlish"));
            // \u00CB == E with diacritic
            Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("U"));

            LanguageSubtag subtag = new LanguageSubtag("qip", "Qipkey", true, null);
            IWritingSystem newWs  = wsManager.Create(subtag, null, null, null);

            wsManager.Set(newWs);
            Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("Qipsing"), "code for 'qip' should already be taken");

            subtag = new LanguageSubtag("aaa", "Qipsing", true, null);
            newWs  = wsManager.Create(subtag, null, null, null);
            wsManager.Set(newWs);
            Assert.AreEqual("aab", wsManager.GetValidLangTagForNewLang("Qipwest"),
                            "code for 'qip' should already be taken twice");

            // ENHANCE: Ideally, we would want to test incrementing the middle and first character,
            // but that would require at least 677 (26^2 + 1) writing systems be created.
        }
		public void GetValidLangCodeForNewLang()
		{
			string storePath = PrepareTempStore("Store");
			string globalStorePath = PrepareTempStore("GlobalStore");

			EnsureDirectoryIsEmpty(storePath);
			EnsureDirectoryIsEmpty(globalStorePath);

			var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
			var wsManager = new PalasoWritingSystemManager(
				new LocalFileWritingSystemStore(storePath, globalStore), globalStore);

			Assert.AreEqual("qip", wsManager.GetValidLangTagForNewLang("Qipkey"));
			Assert.AreEqual("sn", wsManager.GetValidLangTagForNewLang("Sn"));
			Assert.AreEqual("eba", wsManager.GetValidLangTagForNewLang("\u00CBbashlish")); // \u00CB == E with diacritic
			Assert.AreEqual("eee", wsManager.GetValidLangTagForNewLang("\u00CB\u00CB\u00CBlish"));
			// \u00CB == E with diacritic
			Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("U"));

			LanguageSubtag subtag = new LanguageSubtag("qip", "Qipkey", true, null);
			IWritingSystem newWs = wsManager.Create(subtag, null, null, null);
			wsManager.Set(newWs);
			Assert.AreEqual("aaa", wsManager.GetValidLangTagForNewLang("Qipsing"), "code for 'qip' should already be taken");

			subtag = new LanguageSubtag("aaa", "Qipsing", true, null);
			newWs = wsManager.Create(subtag, null, null, null);
			wsManager.Set(newWs);
			Assert.AreEqual("aab", wsManager.GetValidLangTagForNewLang("Qipwest"),
				"code for 'qip' should already be taken twice");

			// ENHANCE: Ideally, we would want to test incrementing the middle and first character,
			// but that would require at least 677 (26^2 + 1) writing systems be created.
		}