Exemplo n.º 1
0
        public uint Register(ITranslatedStringGetter str, StringsSource source)
        {
            List <KeyValuePair <Language, string>[]> strs = source switch
            {
                StringsSource.Normal => _strings,
                StringsSource.IL => _ilStrings,
                StringsSource.DL => _dlStrings,
                _ => throw new NotImplementedException(),
            };

            lock (strs)
            {
                var arr = str.ToArray();
                if (!arr.Any(x => !string.IsNullOrEmpty(x.Value)))
                {
                    // Do not insert into strings writer
                    return(0);
                }
                strs.Add(arr);
                try
                {
                    return(checked ((uint)strs.Count));
                }
                catch (OverflowException)
                {
                    throw new OverflowException("Too many translated strings for current system to handle.");
                }
            }
        }
Exemplo n.º 2
0
        public uint Register(ITranslatedStringGetter str, StringsSource source)
        {
            List <KeyValuePair <Language, string>[]> strs = source switch
            {
                StringsSource.Normal => _strings,
                StringsSource.IL => _ilStrings,
                StringsSource.DL => _dlStrings,
                _ => throw new NotImplementedException(),
            };

            lock (strs)
            {
                // ToDo
                // Add Count member to TranslatedString, or something similar to short circuit array creation if unnecessary
                var arr = str.ToArray();
                if (!arr.Any(x => x.Value != null))
                {
                    // Do not insert into strings writer
                    return(0);
                }
                strs.Add(arr);
                try
                {
                    return(checked ((uint)strs.Count));
                }
                catch (OverflowException)
                {
                    throw new OverflowException("Too many translated strings for current system to handle.");
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Attempts to retrieve a string for a specific language.
 /// Default language will always at least return string.Empty, never null.
 /// </summary>
 /// <param name="getter">Translated string to look up on</param>
 /// <param name="language">Language to query</param>
 /// <returns>String if located, otherwise null</returns>
 public static string?Lookup(this ITranslatedStringGetter getter, Language language)
 {
     if (getter.TryLookup(language, out var str))
     {
         return(str);
     }
     if (language == getter.TargetLanguage)
     {
         return(string.Empty);
     }
     return(null);
 }
Exemplo n.º 4
0
 public void Write(
     MutagenWriter writer,
     ITranslatedStringGetter item,
     RecordType header,
     StringBinaryType binaryType,
     StringsSource source)
 {
     using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
     {
         Write(
             writer,
             item,
             binaryType,
             source);
     }
 }
Exemplo n.º 5
0
 public void Write(
     MutagenWriter writer,
     ITranslatedStringGetter item,
     StringBinaryType binaryType,
     StringsSource source)
 {
     if (writer.MetaData.StringsWriter == null)
     {
         writer.Write(
             item.String,
             binaryType: binaryType);
     }
     else
     {
         writer.Write(writer.MetaData.StringsWriter.Register(item, source));
     }
 }
Exemplo n.º 6
0
 public void Write(
     MutagenWriter writer,
     ITranslatedStringGetter item,
     RecordType header,
     StringBinaryType binaryType,
     StringsSource source)
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             Write(
                 writer,
                 item,
                 binaryType,
                 source);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }