Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit creation via an API does not return unit ID. #7603

Closed
2 tasks done
antonkomarev opened this issue May 6, 2022 · 1 comment
Closed
2 tasks done

Unit creation via an API does not return unit ID. #7603

antonkomarev opened this issue May 6, 2022 · 1 comment
Assignees
Labels
enhancement Adding or requesting a new feature.
Milestone

Comments

@antonkomarev
Copy link

antonkomarev commented May 6, 2022

Describe the issue

Unit creation via an API does not return unit identifier. I've tried to make requests with different keys and it's always returns id = 15, but when I'm making GET /api/translations/example-project/messages/en/units/ request — units have ids like 149, 150, 151 and so on. I've tried to use all IDs from the response, but they are all not unit_id.

I already tried

  • I've read and searched the documentation.
  • I've searched for similar issues in this repository.

Steps to reproduce the behavior

  1. Make API request

POST /api/translations/(string: project)/(string: component)/(string: language)/units/

{
    "key": "example_key",
    "value": ["Example translation"]
}
  1. Get id key in the response.

Response:

[
  "language" => array:8 [
    "code" => "en"
    "name" => "English"
    "plural" => array:5 [
      "id" => 143
      "source" => 0
      "number" => 2
      "formula" => "n != 1"
      "type" => 1
    ]
    "aliases" => array:5 [
      0 => "en_en"
      1 => "base"
      2 => "source"
      3 => "enp"
      4 => "eng"
    ]
    "direction" => "ltr"
    "web_url" => "http://weblate.example.com/languages/en/"
    "url" => "http://weblate.example.com/api/languages/en/"
    "statistics_url" => "http://weblate.example.com/api/languages/en/statistics/"
  ]
  "component" => array:56 [
    "name" => "messages"
    "slug" => "messages"
    "id" => 8
    "source_language" => array:8 [
      "code" => "en"
      "name" => "English"
      "plural" => array:5 [
        "id" => 143
        "source" => 0
        "number" => 2
        "formula" => "n != 1"
        "type" => 1
      ]
      "aliases" => array:5 [
        0 => "en_en"
        1 => "base"
        2 => "source"
        3 => "enp"
        4 => "eng"
      ]
      "direction" => "ltr"
      "web_url" => "http://weblate.example.com/languages/en/"
      "url" => "http://weblate.example.com/api/languages/en/"
      "statistics_url" => "http://weblate.example.com/api/languages/en/statistics/"
    ]
    "project" => array:17 [
      "name" => "example-project"
      "slug" => "example-project"
      "id" => 4
      "web" => "https://example.com"
      "web_url" => "http://weblate.example.com/projects/example-project/"
      "url" => "http://weblate.example.com/api/projects/example-project/"
      "components_list_url" => "http://weblate.example.com/api/projects/example-project/components/"
      "repository_url" => "http://weblate.example.com/api/projects/example-project/repository/"
      "statistics_url" => "http://weblate.example.com/api/projects/example-project/statistics/"
      "changes_list_url" => "http://weblate.example.com/api/projects/example-project/changes/"
      "languages_url" => "http://weblate.example.com/api/projects/example-project/languages/"
      "translation_review" => false
      "source_review" => false
      "set_language_team" => true
      "instructions" => ""
      "enable_hooks" => true
      "language_aliases" => ""
    ]
    "vcs" => "git"
    "repo" => "git@github.com/example/repo.git"
    "git_export" => "http://weblate.example.com/git/example-project/messages/"
    "branch" => "master"
    "push_branch" => "master"
    "filemask" => "example-project/messages+intl-icu.*.xlf"
    "template" => "example-project/messages+intl-icu.en.xlf"
    "edit_template" => true
    "intermediate" => ""
    "new_base" => "example-project/messages+intl-icu.en.xlf"
    "file_format" => "xliff"
    "license" => ""
    "license_url" => null
    "agreement" => ""
    "web_url" => "http://weblate.example.com/projects/example-project/messages/"
    "url" => "http://weblate.example.com/api/components/example-project/messages/"
    "repository_url" => "http://weblate.example.com/api/components/example-project/messages/repository/"
    "translations_url" => "http://weblate.example.com/api/components/example-project/messages/translations/"
    "statistics_url" => "http://weblate.example.com/api/components/example-project/messages/statistics/"
    "lock_url" => "http://weblate.example.com/api/components/example-project/messages/lock/"
    "links_url" => "http://weblate.example.com/api/components/example-project/messages/links/"
    "changes_list_url" => "http://weblate.example.com/api/components/example-project/messages/changes/"
    "task_url" => null
    "new_lang" => "add"
    "language_code_style" => ""
    "push" => "git@github.com/example/repo.git"
    "check_flags" => ""
    "priority" => 100
    "enforced_checks" => []
    "restricted" => false
    "repoweb" => ""
    "report_source_bugs" => ""
    "merge_style" => "rebase"
    "commit_message" => """
      Translated using Weblate ({{ language_name }})\n
      \n
      Currently translated at {{ stats.translated_percent }}% ({{ stats.translated }} of {{ stats.all }} strings)\n
      \n
      Translation: {{ project_name }}/{{ component_name }}\n
      Translate-URL: {{ url }}
      """
    "add_message" => """
      Added translation using Weblate ({{ language_name }})\n
      \n
      """
    "delete_message" => """
      Deleted translation using Weblate ({{ language_name }})\n
      \n
      """
    "merge_message" => """
      Merge branch '{{ component_remote_branch }}' into Weblate.\n
      \n
      """
    "addon_message" => """
      Update translation files\n
      \n
      Updated by "{{ addon_name }}" hook in Weblate.\n
      \n
      Translation: {{ project_name }}/{{ component_name }}\n
      Translate-URL: {{ url }}
      """
    "allow_translation_propagation" => true
    "manage_units" => true
    "enable_suggestions" => true
    "suggestion_voting" => false
    "suggestion_autoaccept" => 0
    "push_on_commit" => true
    "commit_pending_age" => 24
    "auto_lock_error" => true
    "language_regex" => "^[^.]+$"
    "variant_regex" => ""
    "addons" => []
    "is_glossary" => false
    "glossary_color" => "silver"
  ]
  "language_code" => "en"
  "id" => 15
  "filename" => "example-project/messages+intl-icu.en.xlf"
  "revision" => "acc626fcdd513bccaa97185c5d7cd6e343aec8b4,acc626fcdd513bccaa97185c5d7cd6e343aec8b4"
  "web_url" => "http://weblate.example.com/projects/example-project/messages/en/"
  "share_url" => "http://weblate.example.com/engage/example-project/en/"
  "translate_url" => "http://weblate.example.com/translate/example-project/messages/en/"
  "url" => "http://weblate.example.com/api/translations/example-project/messages/en/"
  "is_template" => true
  "is_source" => true
  "total" => 9
  "total_words" => 42
  "translated" => 9
  "translated_words" => 42
  "translated_percent" => 100.0
  "fuzzy" => 0
  "fuzzy_words" => 0
  "fuzzy_percent" => 0.0
  "failing_checks" => 0
  "failing_checks_words" => 0
  "failing_checks_percent" => 0.0
  "have_suggestion" => 0
  "have_comment" => 0
  "last_change" => "2022-05-06T06:08:52.940820Z"
  "last_author" => "Weblate Admin"
  "repository_url" => "http://weblate.example.com/api/translations/example-project/messages/en/repository/"
  "file_url" => "http://weblate.example.com/api/translations/example-project/messages/en/file/"
  "statistics_url" => "http://weblate.example.com/api/translations/example-project/messages/en/statistics/"
  "changes_list_url" => "http://weblate.example.com/api/translations/example-project/messages/en/changes/"
  "units_list_url" => "http://weblate.example.com/api/translations/example-project/messages/en/units/"
]

Here is PHP code which I used to reproduce the error:

<?php

$project = 'example-project';
$component = 'messages';
$language = 'en';

$baseUri = 'https://weblate.example.com';
$uri = "/api/translations/$project/$component/$language/units/";
$url = $baseUri . $uri;
$headers = [
    'Authorization' => 'Token {SECRET_TOKEN}',
    'Content-Type' => 'application/json',
];

$key = 'example_key';
$body = json_encode(
    [
        'key' => $key,
        'value' => [
            $key,
        ],
    ]
);

$httpClient = \Symfony\Component\HttpClient\HttpClient::create();
try {
    $response = $httpClient->request('POST', $url, ['body' => $body, 'headers' => $headers]);
    $content = $response->toArray();
    $unitId = $content['id'];
    
    var_dump('Unit id: ' . $unitId);
} catch (\Throwable $exception) {
    var_dump('Exception!');
    var_dump('Code: ' . $exception->getCode());
    var_dump('Message: ' . $exception->getMessage());
}

Expected behavior

Response have id of the created Unit.

Screenshots

No response

Exception traceback

No response

How do you run Weblate?

Docker container

Weblate versions

Weblate 4.11.2

Weblate deploy checks

No response

Additional context

No response

@nijel nijel self-assigned this May 6, 2022
@nijel nijel added the enhancement Adding or requesting a new feature. label May 6, 2022
@nijel nijel added this to To do in API improvements via automation May 6, 2022
@nijel nijel added this to the 4.13 milestone May 6, 2022
@nijel nijel closed this as completed in b6ab48f May 6, 2022
API improvements automation moved this from To do to Done May 6, 2022
@github-actions
Copy link

github-actions bot commented May 6, 2022

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature.
Projects
Status: Done
Development

No branches or pull requests

2 participants