Split public and private i18n APIs #6022

Merged
Jackenmen merged 3 commits from i18n_api_changes_for_rarely_used into V3/develop 2025-01-27 01:33:06 +01:00
Jackenmen commented 2023-04-15 20:45:21 +02:00 (Migrated from github.com)

Description of the changes

  • Move private i18n APIs to redbot.core._i18n and name them more sensibly (set_locale, set_regional_format, and reload_locales which I've moved to redbot.core._i18n and renamed to set_global_locale, set_global_regional_format, and _reload_locales)
  • Prefix get_locale_path() with _
  • Publicize and document set_contextual_locale() and set_contextual_regional_format()
    • changed set_contextual_locale() and set_contextual_regional_format() to verify input
  • Altered the ContextVar logic to not keep a default value and instead pass the default value to context_var.get() call

Have the changes in this PR been tested?

Yes

### Description of the changes - Move private i18n APIs to `redbot.core._i18n` and name them more sensibly (`set_locale`, `set_regional_format`, and `reload_locales` which I've moved to `redbot.core._i18n` and renamed to `set_global_locale`, `set_global_regional_format`, and `_reload_locales`) - Prefix `get_locale_path()` with `_` - Publicize and document `set_contextual_locale()` and `set_contextual_regional_format()` - changed `set_contextual_locale()` and `set_contextual_regional_format()` to verify input - Altered the ContextVar logic to not keep a default value and instead pass the default value to `context_var.get()` call ### Have the changes in this PR been tested? Yes
Flame442 (Migrated from github.com) approved these changes 2025-01-27 01:32:55 +01:00
Flame442 (Migrated from github.com) left a comment

bop

![bop](https://github.com/user-attachments/assets/6987f1cb-b502-4b99-98f7-2b85f947c6be)
Skyridr commented 2025-02-05 10:26:21 +01:00 (Migrated from github.com)

Is there any specific reason why this breaks the entire bot running inside an incus container? Even if local is set to en_US (was C previously), the bot won't start up.

[2025-02-05 08:20:52] [DEBUG] red.main: ====Basic Config====
[2025-02-05 08:20:52] [DEBUG] red.main: Data Path: /home/eve/eve
[2025-02-05 08:20:52] [DEBUG] red.main: Storage Type: JSON
[2025-02-05 08:20:52] [CRITICAL] red.main: The main bot task didn't handle an exception and has crashed
Traceback (most recent call last):
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 40, in _get_standardized_locale_name
locale = Locale.parse(language_code, sep="-")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/eve/redenv/lib/python3.11/site-packages/babel/core.py", line 349, in parse
raise ValueError(msg) # parse_locale would raise a ValueError, so let's do that here
^^^^^^^^^^^^^^^^^^^^^
ValueError: ("Empty locale identifier value: ''\n\nIf you didn't explicitly pass an empty value to a Babel function, this could be caused by there being no suitable locale environment variables for the API you tried to use.",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/main.py", line 470, in red_exception_handler
red_task.result()
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/main.py", line 369, in run_bot
await red.start(token)
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 1278, in start
await self._pre_login()
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 1150, in _pre_login
_i18n.set_global_regional_format(i18n_regional_format)
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 60, in set_global_regional_format
language_code = _get_standardized_locale_name(language_code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 42, in _get_standardized_locale_name
raise ValueError("Invalid language code. Use format: en-US")
ValueError: Invalid language code. Use format: en-US
[2025-02-05 08:20:52] [WARNING] red.main: Attempting to die as gracefully as possible...
[2025-02-05 08:20:52] [INFO] red.main: Shutting down from unhandled exception
[2025-02-05 08:20:52] [ERROR] asyncio: Task exception was never retrieved
future: <Task finished name='Task-2' coro=<shutdown_handler() done, defined at /home/eve/redenv/lib/python3.11/site-packages/redbot/main.py:425> exception=AttributeError("'Red' object has no attribute '_AutoShardedClient__queue'")>
Traceback (most recent call last):
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/main.py", line 441, in shutdown_handler
await red.close()
File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 2259, in close
await super().close()
File "/home/eve/redenv/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 247, in close
await super().close() # type: ignore
^^^^^^^^^^^^^^^^^^^^^
File "/home/eve/redenv/lib/python3.11/site-packages/discord/shard.py", line 498, in close
await self._closing_task
File "/home/eve/redenv/lib/python3.11/site-packages/discord/shard.py", line 495, in _close
self.__queue.put_nowait(EventItem(EventType.clean_close, None, None))
^^^^^^^^^^^^
AttributeError: 'Red' object has no attribute '_AutoShardedClient__queue'

Is there any specific reason why this breaks the entire bot running inside an incus container? Even if local is set to en_US (was C previously), the bot won't start up. > [2025-02-05 08:20:52] [DEBUG] red.main: ====Basic Config==== > [2025-02-05 08:20:52] [DEBUG] red.main: Data Path: /home/eve/eve > [2025-02-05 08:20:52] [DEBUG] red.main: Storage Type: JSON > [2025-02-05 08:20:52] [CRITICAL] red.main: The main bot task didn't handle an exception and has crashed > Traceback (most recent call last): > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 40, in _get_standardized_locale_name > locale = Locale.parse(language_code, sep="-") > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/home/eve/redenv/lib/python3.11/site-packages/babel/core.py", line 349, in parse > raise ValueError(msg) # `parse_locale` would raise a ValueError, so let's do that here > ^^^^^^^^^^^^^^^^^^^^^ > ValueError: ("Empty locale identifier value: ''\n\nIf you didn't explicitly pass an empty value to a Babel function, this could be caused by there being no suitable locale environment variables for the API you tried to use.",) > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/__main__.py", line 470, in red_exception_handler > red_task.result() > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/__main__.py", line 369, in run_bot > await red.start(token) > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 1278, in start > await self._pre_login() > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 1150, in _pre_login > _i18n.set_global_regional_format(i18n_regional_format) > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 60, in set_global_regional_format > language_code = _get_standardized_locale_name(language_code) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/_i18n.py", line 42, in _get_standardized_locale_name > raise ValueError("Invalid language code. Use format: `en-US`") > ValueError: Invalid language code. Use format: `en-US` > [2025-02-05 08:20:52] [WARNING] red.main: Attempting to die as gracefully as possible... > [2025-02-05 08:20:52] [INFO] red.main: Shutting down from unhandled exception > [2025-02-05 08:20:52] [ERROR] asyncio: Task exception was never retrieved > future: <Task finished name='Task-2' coro=<shutdown_handler() done, defined at /home/eve/redenv/lib/python3.11/site-packages/redbot/__main__.py:425> exception=AttributeError("'Red' object has no attribute '_AutoShardedClient__queue'")> > Traceback (most recent call last): > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/__main__.py", line 441, in shutdown_handler > await red.close() > File "/home/eve/redenv/lib/python3.11/site-packages/redbot/core/bot.py", line 2259, in close > await super().close() > File "/home/eve/redenv/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 247, in close > await super().close() # type: ignore > ^^^^^^^^^^^^^^^^^^^^^ > File "/home/eve/redenv/lib/python3.11/site-packages/discord/shard.py", line 498, in close > await self._closing_task > File "/home/eve/redenv/lib/python3.11/site-packages/discord/shard.py", line 495, in _close > self.__queue.put_nowait(EventItem(EventType.clean_close, None, None)) > ^^^^^^^^^^^^ > AttributeError: 'Red' object has no attribute '_AutoShardedClient__queue'
Jackenmen commented 2025-02-05 11:14:30 +01:00 (Migrated from github.com)

See #6517. Our guess is that invalid configuration (which this is caused by) could have been introduced by some version of 3rd-party dashboard cog. We've only seen a single report of this other than yours so we haven't rushed a hot fix release.

See #6517. Our guess is that invalid configuration (which this is caused by) could have been introduced by some version of 3rd-party dashboard cog. We've only seen a single report of this other than yours so we haven't rushed a hot fix release.
Skyridr commented 2025-02-05 11:30:49 +01:00 (Migrated from github.com)

See #6517. Our guess is that invalid configuration (which this is caused by) could have been introduced by some version of 3rd-party dashboard cog. We've only seen a single report of this other than yours so we haven't rushed a hot fix release.

Ty, that fixed it! :)

> See #6517. Our guess is that invalid configuration (which this is caused by) could have been introduced by some version of 3rd-party dashboard cog. We've only seen a single report of this other than yours so we haven't rushed a hot fix release. Ty, that fixed it! :)
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6022
No description provided.