Repository: sphinx-doc/sphinx

Issue:
Duplicate letter in genindex.html in translated html build
### Describe the bug

When using sphinx internationalisation feature and the html builder, the generated index page (genindex.html) sometimes has duplicated letter headers and summary.

See following screenshots:

![2024-06-30-141813_483x127_scrot](https://github.com/sphinx-doc/sphinx/assets/23519418/a7eecf57-fa8f-4d68-be00-05d64d99913d)
![2024-06-30-143930_443x400_scrot](https://github.com/sphinx-doc/sphinx/assets/23519418/3fbc7575-0da7-4ccb-a1d5-a9c45352a5a5)

Online example: <https://club1.fr/docs/en/genindex.html>

EDIT: I just realized the index is in fact a lot more messed up than what I initially thought:
![2024-06-30-152141_528x593_scrot](https://github.com/sphinx-doc/sphinx/assets/23519418/e5b39074-59cc-4c47-93d2-8116b3d0571d)


### How to Reproduce

I made a reproducer based on a stripped down version of our docs:

```sh
git clone --depth=1 --branch=bug-i18n-genindex-duplicate-letter https://github.com/club-1/docs
cd docs/
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
sphinx-build -M html . _build -Dlanguage=en
open _build/html/genindex.html
```

### Environment Information

```text
Platform:              linux; (Linux-6.8.12-amd64-x86_64-with-glibc2.38)
Python version:        3.11.9 (main, Apr 10 2024, 13:16:36) [GCC 13.2.0])
Python implementation: CPython
Sphinx version:        7.4.0+/cdc0ce4
Docutils version:      0.20.1
Jinja2 version:        3.1.4
Pygments version:      2.18.0
```


### Sphinx extensions

```python
None
```


### Additional context

_No response_

Discussion:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 26214a182..c36233573 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -86,6 +86,9 @@ Bugs fixed
 * #12331: Resolve data-URI-image-extraction regression from v7.3.0 affecting
   builders without native support for data-URIs in their output format.
   Patch by James Addison.
+* #12494: Fix invalid genindex.html file produced with translated docs
+  (regression in 7.1.0).
+  Patch by Nicolas Peugnet.
 
 Testing
 -------
diff --git a/doc/index.rst b/doc/index.rst
index a0f66b0b1..bf3653c20 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -92,7 +92,7 @@ Sphinx
          :align: center
          :target: https://docs.python.org
 
-         Python Foundation
+         Python
 
       .. figure:: _static/linux-logo.png
          :alt: Linux Logo
diff --git a/sphinx/domains/std/__init__.py b/sphinx/domains/std/__init__.py
index 504c95027..f2cdbc0e8 100644
--- a/sphinx/domains/std/__init__.py
+++ b/sphinx/domains/std/__init__.py
@@ -272,7 +272,7 @@ def split_term_classifiers(line: str) -> tuple[str, str | None]:
     return term, first_classifier
 
 
-def make_glossary_term(env: BuildEnvironment, textnodes: Iterable[Node], index_key: str,
+def make_glossary_term(env: BuildEnvironment, textnodes: Iterable[Node], index_key: str | None,
                        source: str, lineno: int, node_id: str | None, document: nodes.document,
                        ) -> nodes.term:
     # get a text-only representation of the term and register it
@@ -395,7 +395,7 @@ def run(self) -> list[Node]:
 
                 # use first classifier as a index key
                 term = make_glossary_term(self.env, textnodes,
-                                          first_classifier, source, lineno,  # type: ignore[arg-type]
+                                          first_classifier, source, lineno,
                                           node_id=None, document=self.state.document)
                 term.rawsource = line
                 system_messages.extend(sysmsg)
diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py
index c9fb4a25c..35e1a086a 100644
--- a/sphinx/transforms/i18n.py
+++ b/sphinx/transforms/i18n.py
@@ -411,7 +411,7 @@ def apply(self, **kwargs: Any) -> None:
                         self.app, term or '', source, node.line, self.config, settings,  # type: ignore[arg-type]
                     )
                     updater.patch = make_glossary_term(
-                        self.env, patch, first_classifier or '',
+                        self.env, patch, first_classifier,
                         source, node.line, _id, self.document,  # type: ignore[arg-type]
                     )
                     processed = True


Test patch:
diff --git a/tests/test_intl/test_intl.py b/tests/test_intl/test_intl.py
index c0a1569bb..28b1764f4 100644
--- a/tests/test_intl/test_intl.py
+++ b/tests/test_intl/test_intl.py
@@ -938,6 +938,16 @@ def wrap_nest(parenttag, childtag, keyword):
         start_tag2 = "<%s[^>]*>" % childtag
         return fr"{start_tag1}\s*{keyword}\s*{start_tag2}"
     expected_exprs = [
+        wrap('h2', 'Symbols'),
+        wrap('h2', 'C'),
+        wrap('h2', 'E'),
+        wrap('h2', 'F'),
+        wrap('h2', 'M'),
+        wrap('h2', 'N'),
+        wrap('h2', 'R'),
+        wrap('h2', 'S'),
+        wrap('h2', 'T'),
+        wrap('h2', 'V'),
         wrap('a', 'NEWSLETTER'),
         wrap('a', 'MAILING LIST'),
         wrap('a', 'RECIPIENTS LIST'),