Skip to content

Support for Glossary Identifiers - #10517

Open
Arsha-M wants to merge 4 commits into
sphinx-doc:masterfrom
Arsha-M:multiple-glossaries
Open

Arsha-M wants to merge 4 commits into
sphinx-doc:masterfrom
Arsha-M:multiple-glossaries

Conversation

@Arsha-M

@Arsha-M Arsha-M commented Jun 3, 2022 •

Copy link
Copy Markdown

Feature or Bugfix

  • Feature

Purpose

  • Currently, Sphinx supports multiple glossaries, but the same term cannot appear twice. This is improved by adding an identifier to glossaries so that the correct glossary can be referenced.

Detail

  • Added the identifier to the glossary directive
  • Added documentation
  • Added testing

Relates

@Arsha-M
Arsha-M force-pushed the multiple-glossaries branch from c5b1061 to b729b82 Compare June 3, 2022 16:36
@Arsha-M
Arsha-M marked this pull request as ready for review June 3, 2022 16:36
@Arsha-M

Arsha-M commented Jun 3, 2022 •

Copy link
Copy Markdown
Author

Hello! I believe that I am ready for the workflows to be run and for a review. :)

I successfully ran the linter, unit tests, and documentation locally. However, I am sure that I made a mistake somewhere as this is my first contribution.

I don't understand how the i18n.py module works so in the make_glossary_term() call, I passed an empty string as the key. Is this correct?

Also, are you happy with the referencing of the terms? Here is an example of what it looks like:

image

image

image

The source to produce this is:

image

image

Comment thread sphinx/transforms/i18n.py
patch = publish_msgstr(self.app, parts[0], source,
node.line, self.config, settings)
patch = make_glossary_term(self.env, patch, parts[1],
patch = make_glossary_term(self.env, patch, '', parts[1],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

@Arsha-M

Arsha-M commented Jun 17, 2022

Copy link
Copy Markdown
Author

Hello @AA-Turner, gentle ping. I noticed that you have been making most of the merges recently, and I was wondering if I could get approval for running the workflows and a review? 🙏

Thanks!

@Arsha-M

Arsha-M commented Jun 30, 2022

Copy link
Copy Markdown
Author

Hello @AA-Turner, gentle ping. Would I be able to get some feedback on these changes? 🙏

Thanks!

@AA-Turner

Copy link
Copy Markdown
Member

I can review the change, but I want to review the discussion on the overall design first.

A

@AA-Turner AA-Turner added the type:enhancement enhance or introduce a new feature label Jul 2, 2022
@AA-Turner AA-Turner added this to the 5.x milestone Jul 2, 2022
The whole characters in "key" is used instead of a first character; it is
used for "Combining Character Sequence" and "Surrogate Pairs" grouping key.

If you want to specify a "glossary key" to make glossaries unique even if

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel "key" is a bit functional wording. It would be better to use more semantic words (ex. classifier, category, glossary type, and so on).

In my understanding, this PR improves Sphinx to be able to have multiple "kinds" of glossaries. So this document should describe the design as possible. It's an advantage of multiple glossaries. But it's not a main goal.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! 🙏

I will change the term "key" to "classifier", and improve the document.

Comment thread sphinx/domains/std.py

std = cast(StandardDomain, env.get_domain('std'))
std._note_term(termtext, node_id, location=term)
std._note_term(term_reference, node_id, location=term)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to separate the glossary key and term in the domain database. It might cause conflict with a term having colon and a term having a key. No reason to store them in concatenated form.

.. glossary::

   key:term

.. glossary:: key

   term

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't exactly understand what you mean, could you please clarify? I am confused by the code block that you added, and why you don't want them to be stored in concatenated form.

What I am understanding is you would like me to do the following:

std._note_term(termtext, node_id, location=term)

where

termtext = "Term1"

Comment thread sphinx/domains/std.py
# add an index entry too
indexnode = addnodes.index()
indexnode['entries'] = [('single', termtext, node_id, 'main', index_key)]
indexnode['entries'] = [('single', term_reference, node_id, 'main', index_key)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you check how a term having a key is shown on the index? Is it better to prepend the key here?

Comment thread sphinx/domains/std.py
required_arguments = 0
optional_arguments = 0
optional_arguments = 1
final_argument_whitespace = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling this allows users to use phrases to glossary key.

.. glossary:: document writing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tk0miya What do you suggest I do here?

Should I allow this behavior?

Or, check for spaces, and if there are spaces, throw an error?

@tk0miya tk0miya added type:proposal a feature suggestion and removed type:proposal a feature suggestion labels Jul 3, 2022
@tk0miya

tk0miya commented Jul 3, 2022

Copy link
Copy Markdown
Member

I think a title of reference and an index entry should be bare "Term1".

@shimizukawa

Copy link
Copy Markdown
Member

Here is a summary of my opinion.

  1. Sometime I also want to have a type for the term and allow a term with the same name for each type.
  2. In articles, display terms of the same name as they are.
  3. In the Index, display terms of the same name with separated entries so that they are indistinguishable from each other.

In the index, for example,
separated entries as:

term (type1)
term (type2)

or pair style as:

term
    type1
    type2

@Arsha-M

Arsha-M commented Jul 5, 2022 •

Copy link
Copy Markdown
Author

Thanks for the feedback @tk0miya @shimizukawa

I would like to summarize the requested changes before I make them:

  1. Instead of calling it a glossary "key" change it to "classifier".
  2. Improve the documentation
  3. Make it so that the index shows the terms with the different types in a nicer format. as suggested by @shimizukawa
  4. Fix the behavior of the optional_arguments in a manner that @tk0miya suggests.
  5. Improve the way that the "classifier" and term are stored in the domain database.

Thanks again for your feedback, I greatly appreciate it.

@Arsha-M

Arsha-M commented Jul 5, 2022 •

Copy link
Copy Markdown
Author

I think a title of reference and an index entry should be bare "Term1".

Whenever you say "title of reference" do you mean when you do :term:`page2:Term2` , you would like it to be rendered as "Term2" instead of "page2:Term2"?

Alternatively, are you okay with it being rendered as "page2:Term2" by default and require the user to do
:term:`Term2 <page2:Term2>` ?

@n-peugnet

Copy link
Copy Markdown
Contributor

@shimizukawa:

  1. In the Index, display terms of the same name with separated entries so that they are indistinguishable from each other.

In the index, for example, separated entries as:

term (type1)
term (type2)

or pair style as:

term
    type1
    type2

IMO the pair style would be perfect. This would also generate these entries:

type1
    term
type2
    term

But I would like to be able to translate type1 and type2 in other languages.

@AA-Turner AA-Turner modified the milestones: 5.x, 6.x Oct 4, 2022
@AA-Turner
AA-Turner changed the base branch from 5.x to master October 16, 2022 15:28
@AA-Turner AA-Turner modified the milestones: 6.x, 7.x Apr 29, 2023
@AA-Turner AA-Turner removed this from the 7.x milestone Jul 20, 2024
@neongreen-sc

Copy link
Copy Markdown

Whenever you say "title of reference" do you mean when you do :term:page2:Term2 , you would like it to be rendered as "Term2" instead of "page2:Term2"?

I'd also like to voice support for "Term2" by default instead of "page2:Term2".

My usecase is building documentation for several teams working in the same monorepo. Some terms are used differently by different teams. If terms were rendered with category prefixes by default, it means we'd always have to override the reference text.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domains:std type:enhancement enhance or introduce a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better support for multiple glossaries

6 participants