Repository Connector

Set up the Repo Connector to handle different source content

Typically, if you have a different set of languages for different files, then you have to use different smartling-config.json files. You can configure the Repo Connector to handle more than one smartling-config.json, but unfortunately the Repo Connector can only accept one smartling-config.json per repository.

In other words:

  • If you have smartling-config-1.json and smartling-config-2.json in repository /my-app.git then the Repo Connector will pickup only one of configuration files
  • If you have smartling-config-1.json in repository /my-app-1.git and smartling-config-2.json in /my-app-2.git, then it's pretty standard case and the Repo Connector will pull files from /my-app-1.git and /my-app-2.git according to configurations.
As a workaround, you can run multiple instances of the Repo Connector application. If you look at "help" in the below example, you can tell Repo where to look for configuration:
$ java -jar repo-connector-1.5.0.jar
2016-06-03 19:49:27,397 INFO Configuration is cfg
usage: repo-connector
 -configuration <dir>   define configuration directory, default
                        configuration directory is cfg
 -help                  print help message
 -start                 start github listening
 -stop                  stop github listening

This way, you can copy instances of the Repo application and specify different configuration for each one.
Let's say we have the following structure of the original content

site
└───themes
    ├───partials
    │   └───en-DE
    │           footer.html
    │
    └───templates
        ├───en-JP
        │       home.html
        │
        └───en-NL
                home.html

And we want to translate:

  • en-DE -> de-DE
    en-DE -> nl-NL
    
  • en-JP -> zh-CN
    en-JP -> es-ES
    
  • en-NL -> nl-NL
    en-NL -> ru-RU
    

First, you prepare 3 different smartling-config.json files. You can commit them in the repository or keep on the server side together with repo-connector.conf. Below examples of target files:

Example 1

{
// en-DE will be translated only to 2 languages: de-DE and nl-NL
"locales": [
{
"smartling" : "de-DE",
"application" : "de-DE"
},
{
"smartling" : "nl-NL",
"application" : "nl-NL"
}
],

"resourceSets": [
{
"type" : "html",
// Select all files under site/themes folder and also have en-DE folder in the path
"pathRegex" : "site\\/themes\\/(?<subFolders>.*)\\/en-DE\\/(?<filePath>.*)\\.html",
"translationPathExpression" : "/site/themes/${subFolders}/${locale}/${filePath}.${originalFile.extension}",
"translationCommitMessage" : "Translated ${originalFile.fullName} to ${locale}",
"smartlingDirectives" : ["smartling.placeholder_format_custom = \\{\\{.+?\\}\\}"]
}
]
}

Example 2

{
// en-JP will be translated only to 2 languages: zh-CN and es-ES
"locales": [
{
"smartling" : "zh-CN",
"application" : "zh-CN"
},
{
"smartling" : "es",
"application" : "es-ES"
}
],

"resourceSets": [
{
"type" : "html",
// Select all files under site/themes folder and also have en-JP folder in the path
"pathRegex" : "site\\/themes\\/(?<subFolders>.*)\\/en-JP\\/(?<filePath>.*)\\.html",
"translationPathExpression" : "/site/themes/${subFolders}/${locale}/${filePath}.${originalFile.extension}",
"translationCommitMessage" : "Translated ${originalFile.fullName} to ${locale}",
"smartlingDirectives" : ["smartling.placeholder_format_custom = \\{\\{.+?\\}\\}"]
}
]
}

Example 3

{
// en-NL will be translated only to 2 languages: de-DE and nl-NL
"locales": [
{
"smartling" : "nl-NL",
"application" : "nl-NL"
},
{
"smartling" : "ru-RU",
"application" : "ru-RU"
}
],

"resourceSets": [
{
"type" : "html",
// Select all files under site/themes folder and also have en-NL folder in the path
"pathRegex" : "site\\/themes\\/(?<subFolders>.*)\\/en-NL\\/(?<filePath>.*)\\.html",
"translationPathExpression" : "/site/themes/${subFolders}/${locale}/${filePath}.${originalFile.extension}",
"translationCommitMessage" : "Translated ${originalFile.fullName} to ${locale}",
"smartlingDirectives" : ["smartling.placeholder_format_custom = \\{\\{.+?\\}\\}"]
}
]
}

All 3 example files above can be committed into the repository like so:

smartling-config-en-DE.json
smartling-config-en-JP.json
smartling-config-en-NL.json

site
└───themes
    ├───partials
    │   └───en-DE
    │           footer.html
    │
    └───templates
        ├───en-JP
        │       home.html
        │
        └───en-NL
                home.html

Next configure the Repo Connector.

In the example above, we want to run 3 instances of the Repo Connector. The configuration folder path should be passed into the command line.

Copy existing "cfg" folder into "cfg-en-DE", "cfg-en-JP" and "cfg-nl-NL". The Repo Connector folder now contains the following:

readme.txt
repo-connector-1.5.0.jar
smartling-config-example.json
activemq-data
cfg-en-DE
    logback.xml
    repo-connector.conf

cfg-en-JP
    logback.xml
    repo-connector.conf

cfg-en-NL
    logback.xml
    repo-connector.conf

lib
    activation-1.1.jar
    ...

Next, modify repo-connector.conf in each folder

  1. Set git url and git credentials
  2. Set proper resourcesConfig. An example, you configure for en-DE folder, then
    "resourcesConfig": "smartling-config-en-DE.json",
    

    for en-NL will be

    "resourcesConfig": "smartling-config-en-NL.json",
    
  3. Set unique ports for http listeners (we use them for managing the Repo Connector status and Webhooks\Callbacks)
      "manager": {
        // port for status and stop commands transmission. Choose any free port differ from http one
        // If you want to start several repo-connector instances each of them must have it own unique port
        "managePort" : "7777"
      },
    
      // Settings for repo-connector http listener
      "http": {
        // Port for the Webhooks and Callback listeners. Choose any free port.
        // If you want to start several repo-connector instances each of them must have it own unique port
        "port": "5555",
      }
    

     

Now you can start 3 instances of the same the Repo Connector app, but with different configurations.

java -jar repo-connector-1.5.0.jar -configuration ./cfg-en-DE -start
java -jar repo-connector-1.5.0.jar -configuration ./cfg-en-JP -start
java -jar repo-connector-1.5.0.jar -configuration ./cfg-en-NL -start

 

Using the above steps, one file was translated, /github_test/multiple-configurations/site/themes/partials/en-DE/footer.html, and only the first Repo Connector application picked up changes and pushed it to repository. Now you can find the new file in repository (site/themes/partials/de-DE/footer.html)

smartling-config-en-DE.json
smartling-config-en-JP.json
smartling-config-en-NL.json

site
└───themes
    ├───partials
    │   ├───de-DE
    │   │       footer.html
    │   │
    │   └───en-DE
    │           footer.html
    │
    └───templates
        ├───en-JP
        │       home.html
        │
        └───en-NL
                home.html

 

Was this article helpful?