Skip to content

Conversation

ValentinBossi
Copy link
Contributor

@ValentinBossi ValentinBossi commented Aug 26, 2025

resolves #930

Copy link
Collaborator

@Aukevanoost Aukevanoost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea,
As you mentioned this fix is indeed satisfying the allowed options of locales.

Unfortunately however, it is also allowed to have a simple string as value, which also returns false on "Array.isArray".

I'd suggest going for:

const locales = [["a", "b"], "c", {"translation": "d"}, {"translation": ["e", "f"]}, ]

const translationFiles = locales
    .map((config) => {
      if (Array.isArray(config)) return config.join(", ")
      if (config.translation) return (Array.isArray(config.translation)) ? config.translation.join(", ") : config.translation
      
      return config;
    })
    .map((value) => JSON.stringify(`[${value}]`))
    .join(' ');

console.log(translationFiles);

Output: "[a, b]" "[c]" "[d]" "[e, f]"

This should satisfy the localize spec, What do you think?

@ashurkovdev
Copy link

Great idea, As you mentioned this fix is indeed satisfying the allowed options of locales.

Unfortunately however, it is also allowed to have a simple string as value, which also returns false on "Array.isArray".

I'd suggest going for:

const locales = [["a", "b"], "c", {"translation": "d"}, {"translation": ["e", "f"]}, ]

const translationFiles = locales
    .map((config) => {
      if (Array.isArray(config)) return config.join(", ")
      if (config.translation) return (Array.isArray(config.translation)) ? config.translation.join(", ") : config.translation
      
      return config;
    })
    .map((value) => JSON.stringify(`[${value}]`))
    .join(' ');

console.log(translationFiles);

This suggestion fails with the example below:

    "locales": {
      "ru": {
        "baseHref": "",
        "translation": "i18n/ru.json"
      }
    }

But PR works as well for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support object config for locales in angular.json
3 participants