Configuration File Inheritance

As you will later see from Serge configuration file reference, there are many configuration parameters that are likely to be shared among different localization jobs. So if you're using Serge to localize more than one simple project with files of just one type, then you're going to have multiple configuration files, and it makes sense to externalize common settings and reference them in multiple places.

Serge configuration files support a powerful way to externalize common settings, and then inherit and override them at any level of your configuration tree. Consider the following example:


Here, the @inherit directive tells which settings to inherit the current block structure from. .#inc/common indicates that we need to take the current configuration file (.) and search for inc → job-common block in it, then use its contents to populate the block that contains the @inherit directive, then apply overrides described in that block.

Adding a minus sign before any parameter name (for example, -parameter2) removes the parameter. Similarly, adding a plus sign (e.g., +parameter3) treats the value as an array, and appends the new value to the end of that array.

While Serge files allow you to contain an inc block where you can keep your common includes, you can also externalize them into a separate file (and this file can have any arbitrary structure):

Given the example above, once all inheritance instructions are applied, the structure of example-project.serge file will be interpreted by Serge as following:


Multiple Inheritance

The @inherit directive allows one to specify more than one block reference. Each block is interpreted from left to right (the first inherited block structure is applied, then the second one, and so on). Each next inherited block overrides settings accumulated previously. This allows you to have some global settings in a separate file, then some common local setting defined in a particular configuration file that may override global settings. Consider the example below:

Given these two files, the resulting interpreted structure will be:


Testing Inheritance Rules

Internally, Serge uses Config::Neat library that implements this inheritable configuration file format, and this library, which is installed as a prerequisite for Serge, comes with the dump-nconf utility that you can use to preview the final config structure.

So if you have a file my-config.serge which has @inherit statements, you can run this command and it will dump your expanded config into STDOUT:

dump-nconf my-config.serge