Sphinx roles in glossary

I would like to add Sphinx roles (e.g. :ref:`some-link`, :class:`someClass`, meth:`some_method`) to my python-doc organization’s glossary so I can be sure that they are not missing in the translations.

I tried adding them as shown in the above examples, but Transifex will not match them in the source string.

I was only successful when matching “:ref:`Availability”, probably because it ends with letter characters (differently form the above examples).

How can I add sphinx roles to glossary and have them successfully match in source string?

Hello @rffontenelle,

Thank you for reaching out to Transifex support.
By what you mentioned I assume you are looking for some type of variables to match whatever text is after certain words, Am I right ? for example “class: $textVariables”. If this is the case then our Glossary is not an option as there is no logic but to match the specific text between the string and the glossary. Perhaps our Translation Checks could help you achieve what you need, Please give it a try and let me know if you have any further questions.

Best Regards
Cesar

2 Likes

Hi @Cesar_Garcia

Working in your suggestion I tried adding custom placeholder like :...:`, :[a-zA-Z]+:` , and :class:` as an attempt to match the beginning of occurrences like e.g. :class:`turtle`, however it didn’t see it as a placeholder in the Editor.

Any idea what did I do wrong?

1 Like

Hello @rffontenelle ,

I have created a placeholder on my personal organization following your example and it seems to be working:

As you can see on the above image, I Allowed whitespace and ended with a comma

Now, In the editor, we can see that the placeholder was recognized
Let me know if this example helps or if you encounter any further issues
Best Regards
Cesar

1 Like

Hi @Cesar_Garcia

Thanks for your reply.

After reading your message, I realized that I was trying to enter placeholders using the “Enter a custom variable” field, and, for some reason, entering placeholders like :class:`...` didn’t work.

However when I used your strategy and used “Starts with:” and “Ends with” fields, the placeholders worked! For instance, I set :class:` as start and ` as end, and now occurrences like :class:`turtle` are successfully considered placeholders!

Thanks!

1 Like

But this means you have to create one for each role… Would it work defining two overlapping placeholders:

  • one for roles names: starting with “:”, ending with “:`”,
  • one for roles values: starting with “:`”, ending with “`”.
1 Like

Genius. It turned 54 placeholders into 2, and works perfectly. Thanks.

EDIT: Actually, only the first custom placeholder is matched, and the second one is ignored. Looks like the first match of :` makes it impossible to match the second placeholder.

Hello @rffontenelle,

I apologize for the inconvenience, Yes, This is expected behavior as order matters inside placeholders, meaning that if the first instance is a match then the 2nd one will be ignored :frowning:

Best Regards
Cesar

2 Likes

Almost ! :rofl:

My proposal was an attempt by feared such behaviors (ordering and first match)

1 Like

Yeah, the idea was awesome. Totally worth trying.

I wish I could regex somehow like :[\w]+:`, but doesn’t seem to work. I read in the docs it is not available for free plans (quoting the docs: Custom translation checks is a feature available on Premium and Enterprise plans).

1 Like

Thought about it too but feared a technical/security reason for not implementing them…

… but that looks like a marketing choice, actually :confused:
If I can understand it for private projects, I believe it is an error to not bundle it for public/open source projects.

If this is for the docs of the project I think it is, maybe Transifex could grant it at least a Premium plan…

TY

1 Like

Hello @silopolis @rffontenelle

We really appreciate your feedback, I have forwarded your comments to my product team.
As you already mention REGEX is only available for premium plans and up, at least for now.

@rffontenelle UPDATE
Please receive my apologies as I forgot to mention that order matters when placing translation checks. Could you try to perform the following and see how it goes ?

  • one for roles values: starting with “:”, ending with “”.
  • one for roles names: starting with “:”, ending with “:`”,

Best Regards
Cesar

1 Like

Hi, @Cesar_Garcia

Sorry for taking too long to reply, but I wasn’t notified of your message update.

I tried your suggestion and what happened was that only the first custom placeholder was applied, and the second one was ignored. For instance, the expression :data:`sys.path_hooks` becomes :data:`sys.path_hooks` (i.e. only :`sys.path_hooks` becomes a placeholder, while the :data is left as a normal text.)

I assume the second placeholder didn’t kick in because the ending :` already met the previous custom placeholder.

Thanks for the suggestion anyway.

2 Likes

Hello @rffontenelle ,

I apologize for the delay.
Regarding your last comment, As I mentioned before, This is expected behavior as order matters inside placeholders, meaning that if the first instance is a match, then the 2nd one will be ignored :frowning: Unfortunately, there is no workaround to avoid this as is part of our logic but in case you have any other questions please feel free to reach out to us.

Best Regards