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

Translation id chooser heuristics are not ok for some edge cases #412

Open
tiberiuichim opened this issue Mar 19, 2023 · 1 comment
Open

Comments

@tiberiuichim
Copy link

def __call__(self, parent, language):
content_id = self.context.getId()
splitted = content_id.split("-")
# ugly heuristic (searching for something like 'de', 'en' etc.)
if len(splitted) > 1 and len(splitted[-1]) == 2:
content_id = "-".join(splitted[:-1])
while content_id in parent.objectIds():
content_id = f"{content_id}-{language}"
return content_id

It should regenerate a new id in the context of the new parent.

If I have an id like items-74, it tries to name the translation as items, which triggers:

  Module plone.app.multilingual.api, line 46, in translate
  Module plone.app.multilingual.manager, line 135, in add_translation
  Module plone.app.multilingual.factory, line 93, in __call__
  Module plone.dexterity.content, line 808, in invokeFactory
  Module Products.CMFCore.PortalFolder, line 299, in invokeFactory
  Module Products.CMFCore.TypesTool, line 809, in constructContent
  Module Products.CMFCore.TypesTool, line 308, in constructInstance
  Module Products.CMFCore.TypesTool, line 570, in _constructInstance
  Module Products.BTreeFolder2.BTreeFolder2, line 436, in _setObject
  Module plone.folder.ordered, line 253, in _checkId
  Module Products.CMFCore.PortalFolder, line 318, in _checkId
  Module OFS.ObjectManager, line 125, in checkValidId
zExceptions.BadRequest: The id "items" is invalid - it is already in use
@lokeshmeesala
Copy link

Hey, I can work on this. In the given example, either content_id is not in parent.objectIds() or 'language' argument is empty. Please let me know how a new id must be generated in these cases. Thanks.

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

No branches or pull requests

3 participants