ToGettextFormat() public static méthode

public static ToGettextFormat ( string text ) : string
text string
Résultat string
Exemple #1
0
        // Converts the header into string representation that can be directly written to .po file as msgid ""
        public string GetHeaderString(string lineDelimeter)
        {
            UpdateHeaderDict();
            StringBuilder sb = new StringBuilder();

            foreach (string key in headerEntries.Keys)
            {
                string value = String.Empty;
                if (headerEntries[key] != null)
                {
                    value = StringEscaping.ToGettextFormat(headerEntries[key]);
                }
                sb.AppendFormat("\"{0}: {1}\\n\"{2}", key, value, lineDelimeter);
            }
            return(sb.ToString());
        }
Exemple #2
0
        //escapes string and lays it out to 80 cols
        static void FormatMessageForFile(StringBuilder sb, string prefix, string message, string newlineChar)
        {
            string escaped = StringEscaping.ToGettextFormat(message);

            //format to 80 cols
            //first the simple case: does it fit one one line, with the prefix, and contain no newlines?
            if (prefix.Length + escaped.Length < 77 && !escaped.Contains("\\n"))
            {
                sb.Append(prefix);
                sb.Append(" \"");
                sb.Append(escaped);
                sb.Append("\"");
                sb.Append(newlineChar);
                return;
            }

            //not the simple case.

            // first line is typically: prefix ""
            sb.Append(prefix);
            sb.Append(" \"\"");
            sb.Append(newlineChar);

            //followed by 80-col width break on spaces
            int  possibleBreak = -1;
            int  currLineLen   = 0;
            int  lastBreakAt   = 0;
            bool forceBreak    = false;

            int pos = 0;

            while (pos < escaped.Length)
            {
                char c = escaped[pos];

                //handle escapes
                if (c == '\\' && pos + 1 < escaped.Length)
                {
                    pos++;
                    currLineLen++;

                    char c2 = escaped[pos];
                    if (c2 == 'n')
                    {
                        possibleBreak = pos + 1;
                        forceBreak    = true;
                    }
                    else if (c2 == 't')
                    {
                        possibleBreak = pos + 1;
                    }
                }

                if (c == ' ')
                {
                    possibleBreak = pos + 1;
                }

                if (forceBreak || (currLineLen >= 77 && possibleBreak != -1))
                {
                    sb.Append("\"");
                    sb.Append(escaped.Substring(lastBreakAt, possibleBreak - lastBreakAt));
                    sb.Append("\"");
                    sb.Append(newlineChar);

                    //reset state for new line
                    currLineLen   = 0;
                    lastBreakAt   = possibleBreak;
                    possibleBreak = -1;
                    forceBreak    = false;
                }
                pos++;
                currLineLen++;
            }
            string remainder = escaped.Substring(lastBreakAt);

            if (remainder.Length > 0)
            {
                sb.Append("\"");
                sb.Append(remainder);
                sb.Append("\"");
                sb.Append(newlineChar);
            }
            return;
        }