0

I am looking for a way to pass information to angular.json file so that I do not need to repeat build configurations and avoid all the code duplication. I can not explain well so I'll try with an example. So In my angular.jsonunder configurations I have something like

"configurations": {
"de": {
              "aot": true,
              "i18nLocale": "de",
              "i18nFile": "project/src/locale/messages.de.xlf",
              "i18nFormat": "xlf"
            },
            "en-gb": {
              "aot": true,
              "i18nLocale": "en-gb",
              "i18nFile": "project/src/locale/messages.en-gb.xlf",
              "i18nFormat": "xlf"
            },
            "en-us": {
              "aot": true,
              "i18nLocale": "en-us",
              "i18nFile": "project/src/locale/messages.en-us.xlf",
              "i18nFormat": "xlf"
            },
            "es": {
              "aot": true,
              "i18nLocale": "es",
              "i18nFile": "project/src/locale/messages.es.xlf",
              "i18nFormat": "xlf"
            },
            "fr": {
              "aot": true,
              "i18nLocale": "fr",
              "i18nFile": "project/src/locale/messages.fr.xlf",
              "i18nFormat": "xlf"
            },
            "it": {
              "aot": true,
              "i18nLocale": "it",
              "i18nFile": "project/src/locale/messages.it.xlf",
              "i18nFormat": "xlf"
            },
            "pt-br": {
              "aot": true,
              "i18nLocale": "pt-br",
              "i18nFile": "project/src/locale/messages.pt-br.xlf",
              "i18nFormat": "xlf"
            }

Is there a way to have a variable like lets say i18n and I can use it in angular.json like $i18n :

"configurations": {
"i18n": {
              "aot": true,
              "i18nLocale": "$i18n",
              "i18nFile": "project/src/locale/messages.$i18n.xlf",
              "i18nFormat": "xlf"
            }

I am not good with english. I hope I explained well using the example for what I am looking for. Thanks in advance.

2
  • 1
    Unfortunately, you can't have this. See stackoverflow.com/questions/23869882/… Commented Nov 12, 2018 at 13:27
  • 1
    this makes me so sad, thanks for the reply! Commented Nov 12, 2018 at 13:48

1 Answer 1

1

I don't speak angular, but in the hope this is useful, I think you're looking at this something like this:

echo '["de","en-gb","en-us","es","fr","it"]' | jq '
  {"configuration":[ .[] as $c |
    {
      ($c):{
         "aot":true,
         "i18nLocale": $c,
         "i18nFile": ("project/src/locale/messages." + $c + ".xlf"),
         "i18nFormat": "xlf"
      }
    }
  ]}'

This command uses jq command line parser to forge a JSON configuration according to your first example.

You can grow the table sent by echo to jq to any country string and get as many configurations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.