Updating a language-specific IProject.SettingsBundle<TranslationMemorySettings> always updates the default settings

While automating the creation of projects, I'm trying to set a custom value inside the following element (inside the project file itself):

        <SettingsBundle Guid="...">
           <SettingsBundle>
               <SettingsGroup Id="TranslationMemorySettings">
                   <Setting Id="ProjectSettings">

I also want to ensure that I'm setting this value on the element specific to the target language, not the default settings.

To achieve this I have the following code (C#):

    01    private void UpdateTmField(IProject project, ITranslationMemory tm, int orderId, Language targetLanguage)
    02    {
    03         var settings = project.GetSettings(targetLanguage);
    04         var tmSettings = settings.GetSettingsGroup<TranslationMemorySettings>();
    05
    06         const string fieldName = "Auftragsnummer";
    07         FieldDefinition field = tm.FieldDefinitions[fieldName];
    08         if (field == null)
    09         {
    10             field = new FieldDefinition(fieldName, FieldValueType.Integer);
    11         }
    12
    13         var fv = (IntFieldValue) field.CreateValue();
    14         fv.Value = orderId;
    15
    16         tmSettings.ProjectSettings.Value = new FieldValues {fv};
    17
    18         project.UpdateSettings(settings);
    19    }

As you can see, I'm specifying the desired language for these settings. [I instantiate the "Language" object with, for example,  new Language("de-CH")]

However, this seems to update only the default settings and not the language-specific settings.

I've tested this two ways:

  1. By using a template with known values in both the language-specific and the default settings sections, I can see which has changed.
  2. By inserting

           tmSettings.ProjectSettings.Reset();

    in line 5 and commenting-out the FieldDefinition-related code. Inside the resultant project file I can see that the default setting's <Setting Id="ProjectSettings"> element has been removed, not the language-specific settings.

Also, after line 5 I can call

        settings.IsDefault

and this returns false - I presume this indicates that the "settings" object is not the default settings and must therefore be a language-specific settings object.

So why do the values that I set appear in the default section instead of the language-specific section?

Parents Reply Children