phrase / phrase-cli

CLI for the Phrase API
https://developers.phrase.com
MIT License
42 stars 6 forks source link

Specifying multiple tags does not create a file for each tag and locale_code but merges all tags into each locale_code file #105

Closed skyfrk closed 1 year ago

skyfrk commented 2 years ago

.phrase.yml

phrase:
  project_id: <projectId>
  push:
    sources:
    - file: ./<tag>/en.json
      params:
        file_format: i18next_4
        locale_id: <enLocaleId>
  pull:
    targets:
    - file: ./<tag>/<locale_code>.json
      params:
        file_format: i18next_4
        tags: namespace1,namespace2

Translations files before phrase pull:

./namespace1/en.json

{
  "Cat": "Cat"
}

./namespace2/en.json

{
  "Dog": "Dog"
}

Translation files after phrase pull (actual)

./namespace1/en.json

{
  "Cat": "Cat",
  "Dog": "Dog"
}

./namespace2/en.json

{
  "Cat": "Cat",
  "Dog": "Dog"
}

Translation files after phrase pull (expected)

./namespace1/en.json

{
  "Cat": "Cat"
}

./namespace2/en.json

{
  "Dog": "Dog"
}

Workaround .phrase.yml

This .phrase.yml yields the expected results but requires one file entry per tag (namespace).

phrase:
  project_id: <projectId>
  push:
    sources:
    - file: ./<tag>/en.json
      params:
        file_format: i18next_4
        locale_id: <enLocaleId>
  pull:
    targets:
    - file: ./<tag>/<locale_code>.json
      params:
        file_format: i18next_4
        tags: namespace1
    - file: ./<tag>/<locale_code>.json
      params:
        file_format: i18next_4
        tags: namespace2
theSoenke commented 2 years ago

Hey @skyfrk, when providing a list of tags the request to fetch the locales is currently passing all provided tags. I agree it would be really useful if each file would only contain keys from one of the tags. There is one request for each tag happening anyway so it seems more helpful to have different sets of keys per file. We'll take a check at what it would take to properly separate the keys in different files by their tag and provide an update here when there is some news

FatalOz commented 1 year ago

Any word on this?

jablan commented 1 year ago

@skyfrk @FatalOz would you mind trying out the latest release?

sarea commented 5 months ago

That did not work for me, all the keys are updated in each file/tag I also tried to remove the tags and add each tag as a file And also specify the file_format like below:

phrase:
  access_token: 123
  project_id: <projectId>
  push:
    sources:
    - file: ./namespace1/en.json
      params:
        file_format: nested_json
        locale_id: 1234
        update_translations: true
        autotranslate: true
    - file: ./namespace2/en.json
      params:
        file_format: nested_json
        locale_id: 1234
        tags: namespace2
        update_translations: true
        autotranslate: true
  pull:
    targets:
    - file: ./namespace1/en.json
      params:
        file_format: nested_json
        locale_id: 1234
        tags: namespace1
    - file: ./namespace2/en.json
      params:
        file_format: nested_json
        locale_id: 1234
        tags: namespace2