Repository: wagtail/wagtail

Issue:
Wagtail 3 removed the ability to manually set root page locale
In Wagtail 2.16 and below, with Wagtail i18n enabled, it is possible to manually select a page's locale when creating it at the Wagtail root. This allows for manual creation of page trees in different languages even without using a translation package like simple_translation or wagtail-localize. This behavior was removed in Wagtail 3.0 and up due to the page editor redesign, perhaps inadvertently.

### Screenshots

In Wagtail 2.16, when creating a page at the Wagtail root, users can select the page locale. In 3.0 and 4.0, this is no longer possible; instead the sidebar shows the default locale and says "No other translations".

|2.16|3.0|4.0|
|-|-|-|
|<img width="1089" alt="image" src="https://user-images.githubusercontent.com/654645/203088594-48dd14e7-c810-4913-aa85-4fc283376540.png">|<img width="1172" alt="image" src="https://user-images.githubusercontent.com/654645/203089001-df18bc66-3fc2-4e08-b5c8-7eb0d6e4457b.png">|<img width="1121" alt="image" src="https://user-images.githubusercontent.com/654645/203089295-4133eb95-701e-46f0-8f78-47f9b1080492.png">|




### Steps to Reproduce

1. Start a new project with `wagtail start myproject`
2. Edit settings.py:
   1. Add `wagtail.locales` to `INSTALLED_APPS`
   2. Define multiple languages:
      ```py
      WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = (
          ("en", "English"),
          ("es", "Spanish"),
      )
      ```
   3. Set `WAGTAIL_I18N_ENABLED = True`
4. Create the database with `./manage.py migrate`
5. Create a superuser with `./manage.py createsuperuser`
6. Run a local server with `./manage.py runserver`
7. Navigate to http://localhost:8000/admin/ and login.
8. Navigate to http://localhost:8000/admin/locales/ and manually add a second locale for Spanish.
9. Navigate to http://localhost:8000/admin/pages/add/home/homepage/1/ to add a new page to the Wagtail root; in 2.16 users have the option of specifying the locale whereas in 3.0+ they do not.

Without this ability, it doesn't seem possible for users to create non-default-locale page trees without the use of a translation framework (or via database scripting). 

The page editor redesign issue #8142 doesn't explicitly call out the ability to do this, but does say that the redesigned side panel should "follow the existing logic of the page locales within the header area of the page editor". The page creation view [still contains code](https://github.com/wagtail/wagtail/blob/682ed3b21fa6924b1e1a6023f80ce7beea570071/wagtail/admin/views/pages/create.py#L365-L385) that mentions that "Pages can be created in any language at the root level", but this code is overriden by [subsequent code](https://github.com/wagtail/wagtail/blob/682ed3b21fa6924b1e1a6023f80ce7beea570071/wagtail/admin/ui/side_panels.py#L187-L208) in the side panel class.

The (excellent) [Wagtail i18n docs](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#translated-homepages) currently say

> This means that to make a site available in another locale, you just need to translate and publish its homepage in that new locale.

but also that

> You don’t strictly have to use i18n_patterns or LocaleMiddleware for this and you can write your own logic if you need to.

It seems like in 2.16 and below, it would be possible to manually create a separate page tree for a different locale and handle traffic as desired (without relying on translation links), but with this change in 3.0 (unless I'm missing something) it doesn't seem at all possible to create non-default-locale pages without using translation.


Discussion:
I'm currently battling the same issue as there seems to be no way to change the root page locale from the admin interface.
Have the same issue... Is there are any workaround to create a separate page tree for a different locale?
@thibaudcolas  how would the new design handle this?

Just a few ideas.

1. (green) we add a tooltip/menu item in the breadcrumbs maybe for choosing the language (although this is more about linking to something else in all other cases)
2. (purple) we add a dropdown in the sidebar under translations, although this again is usually used to show links to other translated variants of the page and the status panel is not really used for 'fields' (except for the exception of the scheduled publishing access).
3. A new field above the Page Title? (risky as it may break with other implementations)
4. A interstitial page before creation that asks you to select the language?

<img width="1511" alt="Screenshot 2023-04-21 at 4 59 27 pm" src="https://user-images.githubusercontent.com/1396140/233563874-61cec39d-d019-4c09-8dcf-e764c2df3ef3.png">

@chosak @madisvain @chuve  - here is a potential work around, assuming you already have one root page created (which, due to this bug, can only be the default language).

On the root page listing, click 'more' & then click 'translate', this will copy the root page that exists and allow you to make another with the different language.

Not ideal but hopefully that unblocks your users for now.

<img width="1447" alt="Screenshot 2023-04-21 at 5 02 36 pm" src="https://user-images.githubusercontent.com/1396140/233565194-341489db-ca91-4db0-9142-fc924c873f4d.png">

<img width="879" alt="Screenshot 2023-04-21 at 5 03 02 pm" src="https://user-images.githubusercontent.com/1396140/233565176-dec2ddd7-6e95-42f3-9d47-ff89e2948a53.png">
Hi @laymonage, thank you for your work addressing this issue.

I just tried the latest main (with #10864) and this still doesn't appear to work as expected. I followed the steps to reproduce I initially filed [above](https://github.com/wagtail/wagtail/issues/9702#issue-1458130311).

When you add a new home page at the Wagtail root you do now have the ability to switch its locale in the sidebar:

![image](https://github.com/wagtail/wagtail/assets/654645/35535bfb-ecac-4fab-a888-2eb6b3ea6575)

And if you select Spanish, the URL changes to http://localhost:8000/admin/pages/add/home/homepage/1/?locale=es, and the sidebar indicates that Spanish has been selected as the new page locale:

![image](https://github.com/wagtail/wagtail/assets/654645/bf2691a5-2110-477c-85bb-b847ac80f7b8)

But if you save draft or publish, that locale setting doesn't seem to affect anything, and the page is still created with the default English locale 😢:

![image](https://github.com/wagtail/wagtail/assets/654645/c537af31-42c1-4175-8e40-1de9fb7c6cb1)

The issue appears to be that this side panel widget doesn't actually contribute the `locale` variable to the POST when the page is saved/published. The page has an `<input type="hidden" name="locale" value="">` element but this isn't getting populated by the locale from query string.

I hope you won't mind if I reopen this issue?
Oops, I admit I didn't actually try saving the page 🙈

Sure, thanks! I'll look into it soon.

Resolving patch:
diff --git a/wagtail/admin/views/pages/create.py b/wagtail/admin/views/pages/create.py
--- a/wagtail/admin/views/pages/create.py
+++ b/wagtail/admin/views/pages/create.py
@@ -390,6 +390,7 @@ def get_context_data(self, **kwargs):
                 "form": self.form,
                 "next": self.next_url,
                 "has_unsaved_changes": self.has_unsaved_changes,
+                "locale": self.locale,
                 "media": media,
             }
         )
@@ -413,7 +414,8 @@ def get_translations(self):
                     + "?"
                     + urlencode({"locale": locale.language_code}),
                 }
-                for locale in Locale.objects.all()
+                # Do not show the switcher for the current locale
+                for locale in Locale.objects.exclude(pk=self.locale.pk)
             ]
 
         else:
diff --git a/wagtail/admin/views/pages/edit.py b/wagtail/admin/views/pages/edit.py
--- a/wagtail/admin/views/pages/edit.py
+++ b/wagtail/admin/views/pages/edit.py
@@ -939,6 +939,7 @@ def get_context_data(self, **kwargs):
                 and user_perms.can_lock(),
                 "user_can_unlock": isinstance(self.lock, BasicLock)
                 and user_perms.can_unlock(),
+                "locale": self.locale,
                 "media": media,
             }
         )


Test patch:
diff --git a/wagtail/admin/tests/pages/test_create_page.py b/wagtail/admin/tests/pages/test_create_page.py
--- a/wagtail/admin/tests/pages/test_create_page.py
+++ b/wagtail/admin/tests/pages/test_create_page.py
@@ -1743,6 +1743,7 @@ def test_locale_selector(self):
 
         self.assertContains(response, 'id="status-sidebar-english"')
 
+        # Should show a link to switch to another locale
         add_translation_url = (
             reverse(
                 "wagtailadmin_pages:add",
@@ -1752,6 +1753,50 @@ def test_locale_selector(self):
         )
         self.assertContains(response, f'href="{add_translation_url}"')
 
+        # Should not show a link to switch to the current locale
+        self_translation_url = (
+            reverse(
+                "wagtailadmin_pages:add",
+                args=["demosite", "homepage", self.root_page.id],
+            )
+            + "?locale=en"
+        )
+        self.assertNotContains(response, f'href="{self_translation_url}"')
+
+    def test_locale_selector_selected(self):
+        response = self.client.get(
+            reverse(
+                "wagtailadmin_pages:add",
+                args=["demosite", "homepage", self.root_page.id],
+            )
+            + "?locale=fr"
+        )
+
+        self.assertContains(response, 'id="status-sidebar-french"')
+
+        # Should render the locale input with the currently selected locale
+        self.assertContains(response, '<input type="hidden" name="locale" value="fr">')
+
+        # Should show a link to switch to another locale
+        add_translation_url = (
+            reverse(
+                "wagtailadmin_pages:add",
+                args=["demosite", "homepage", self.root_page.id],
+            )
+            + "?locale=en"
+        )
+        self.assertContains(response, f'href="{add_translation_url}"')
+
+        # Should not show a link to switch to the current locale
+        self_translation_url = (
+            reverse(
+                "wagtailadmin_pages:add",
+                args=["demosite", "homepage", self.root_page.id],
+            )
+            + "?locale=fr"
+        )
+        self.assertNotContains(response, f'href="{self_translation_url}"')
+
     @override_settings(WAGTAIL_I18N_ENABLED=False)
     def test_locale_selector_not_present_when_i18n_disabled(self):
         response = self.client.get(