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

Support creating local VCS components using API #4156

Closed
2 of 3 tasks
nijel opened this issue Jul 10, 2020 · 6 comments · Fixed by #4553
Closed
2 of 3 tasks

Support creating local VCS components using API #4156

nijel opened this issue Jul 10, 2020 · 6 comments · Fixed by #4553
Assignees
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature.
Milestone

Comments

@nijel
Copy link
Member

nijel commented Jul 10, 2020

Is your feature request related to a problem? Please describe.
The component creation API right now supports only creating components from remote VCS. It should also support no remote VCS setup where initial file is either created by Weblate or provided by upload.

In other words, it should support following workflows supported in the UI:

  • Upload translations files - upload more files in a ZIP
  • Translate document - upload main file
  • Start from scratch - no file provided, starts with blank one

Describe the solution you'd like
Extend https://docs.weblate.org/en/latest/api.html#post--api-projects-(string-project)-components- to support local vcs.

Describe alternatives you've considered
Right now, this is not supported over API, but I don't think it's a viable approach.

Additional context
The related code is currently placed in the view, but should be shared for the API, not sure if it makes sense to move it to the models.

For example, creating component from scratch si here:

def scratch_create_component(project, name, slug, file_format):
format_cls = FILE_FORMATS[file_format]
template = "{}.{}".format(project.source_language.code, format_cls.extension())
fake = Component(project=project, slug=slug, name=name)
# Create VCS with empty file
LocalRepository.from_files(
fake.full_path, {template: format_cls.get_new_file_content()}
)
# Create component
return Component.objects.create(
file_format=file_format,
filemask="*.{}".format(format_cls.extension()),
template=template,
vcs="local",
repo="local:",
project=project,
name=name,
slug=slug,
)

@nijel nijel added the enhancement Adding or requesting a new feature. label Jul 10, 2020
@nijel nijel added this to To do in API improvements via automation Jul 10, 2020
@nijel nijel added the backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. label Jul 10, 2020
@github-actions
Copy link

This issue has been added to the backlog. It is not scheduled on our roadmap, but it eventually might be implemented. In case you desperately need this feature, please consider helping or funding the development.

nijel added a commit that referenced this issue Sep 1, 2020
This allows to use the logic from the API as well.

Issue #4156
@nijel
Copy link
Member Author

nijel commented Sep 1, 2020

I've just implemented basics start from scratch in d9bfab2

@nijel nijel added this to the 4.4 milestone Sep 15, 2020
@nijel nijel linked a pull request Sep 22, 2020 that will close this issue
4 tasks
@nijel nijel modified the milestones: 4.4, 4.3 Sep 22, 2020
@nijel nijel closed this as completed in 9f4bde9 Oct 2, 2020
API improvements automation moved this from To do to Done Oct 2, 2020
@github-actions
Copy link

github-actions bot commented Oct 2, 2020

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, consider supporting Weblate by donating.

nijel added a commit that referenced this issue Oct 2, 2020
@EpocDotFr
Copy link

Thank you!

@walhallyus
Copy link

It's there a way to create a component from scratch through the API?

Basically this is what I want to achieve through api:

  • create a project through api
  • create multiple components through api
  • add strings to components through api
  • translate this strings in weblate UI
  • extract translated strings through api

I would appreciate an opinion from someone, if weblate can help me with that

@nijel
Copy link
Member Author

nijel commented Feb 9, 2022

You need to start from something - either pass zipfile or docfile in the API. The files can be blank, but adding at strings at once will perform better than adding them one by one later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants