/// <summary> /// Returns the translation of <paramref name="msgid"/> and /// <paramref name="msgidPlural"/>, choosing the right plural form /// depending on the number <paramref name="n"/>. /// </summary> /// <param name="msgid">the key string to be translated, an ASCII /// string</param> /// <param name="msgidPlural">the English plural of <paramref name="msgid"/>, /// an ASCII string</param> /// <param name="n">the number, should be >= 0</param> /// <param name="treatZeroAsPlural">if set to true then the number 0 is considered being plural /// (for situations like where strings like "0 records" are to be displayed).</param> /// <returns>the translation, or <c>null</c> if none is found</returns> public static string GetPluralString(String msgid, String msgidPlural, long n, bool treatZeroAsPlural = false) { bool Plural = treatZeroAsPlural ? ((n != 1) && (n != -1)) : (((n != 1) && (n != -1)) && (n != 0)); return(Plural ? msgidPlural : msgid); #if USE_GETTEXT_CATALOG if (catalog == null) { return(Plural ? msgidPlural : msgid); } else { string result = msgid; if ((n == 0)) { // Calling 'catalog.GetPluralString' does not know about our 'treatZeroAsPlural = false' and would return plural in case of n = 0 // so we call 'catalog.GetPluralString' in case 'treatZeroAsPlural = false' ... if (treatZeroAsPlural) { try { result = catalog.GetPluralString(msgid, msgidPlural, n); } catch (Exception Exc) { TLogging.Log( "GetText: Catalog.GetPluralString: problem for getting text for \"" + msgid + "\" and/or \"" + msgidPlural + "\""); TLogging.Log(Exc.ToString()); } return(result); } else { // ...and we make n 1 to get the call to 'catalog.GetPluralString' (further below) to return the singular string! n = 1; } } // Calling 'catalog.GetPluralString' does not work with negative numbers... if (n < 0) { // ...so we make them positive n = n * -1; } try { result = catalog.GetPluralString(msgid, msgidPlural, n); } catch (Exception Exc) { TLogging.Log("GetText: Catalog.GetPluralString: problem for getting text for \"" + msgid + "\" and/or \"" + msgidPlural + "\""); TLogging.Log(Exc.ToString()); } return(result); } #endif }
/// <summary> /// Returns the Value of a specified AppSetting key. /// /// </summary> /// <param name="AKey">Key of the AppSetting</param> /// <param name="ALogErrorIfNotPresent"></param> /// <returns>Value of the AppSetting /// </returns> public static String GetValue(String AKey, Boolean ALogErrorIfNotPresent) { String ReturnValue; XmlElement appsetting = null; ReturnValue = UNDEFINEDVALUE; if (FCmdOpts.IsFlagSet(AKey)) { ReturnValue = FCmdOpts.GetOptValue(AKey); } else { if (FAppSettingsElement != null) { appsetting = (XmlElement)FAppSettingsElement.SelectSingleNode("add[@key='" + AKey + "']"); } if (appsetting != null) { ReturnValue = appsetting.GetAttribute("value"); // TLogging.Log("CustomAppSettings: " + AKey + " = " + ReturnValue); } else { if (ALogErrorIfNotPresent) { try { TLogging.Log( "CustomAppSettings: Cannot find " + AKey + " in command line options or in the config file " + FConfigFileName, TLoggingType.ToConsole | TLoggingType.ToLogfile); } catch (ENoLoggingToFile_WrongConstructorUsedException) { // ignore this Exception; it is thrown if TLogging was not initialised yet, which means no Log file is specified. } } } } ReturnValue = ReturnValue.Replace("{userappdata}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); if ((AKey != "ApplicationDirectory") && (FApplicationDirectory != null)) { ReturnValue = ReturnValue.Replace("{applicationbindir}", ApplicationDirectory); } if (AKey == "OpenPetra.HTTPServer" || AKey == "OpenPetra.Path.RemotePatches") { if (Directory.Exists(TAppSettingsManager.ApplicationDirectory + "/../patches30")) { string [] NameOfInstance = Directory.GetDirectories(TAppSettingsManager.ApplicationDirectory + "/../patches30"); if (NameOfInstance.Length == 1) { ReturnValue = ReturnValue.Replace("placeholder", Path.GetFileName(NameOfInstance[0].ToLower())); } } } return(ReturnValue); }
/// <summary> /// Reset the ticket number to 0 /// </summary> public static void ResetTicket() { TLogging.Log("Resetting ticket number ..."); TicketNum = 0; }