PyAPI: add bpy.utils.manual_locale_code(), use for "Help" menu #104494

Closed
Campbell Barton wants to merge 1 commits from ideasman42:pr-pyapi-manual-fn into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Move the function for getting the language code associated with the
user manual into a utility function (from the generated
rna_manual_reference.py). Use this for all user manual URL references.


After checking on !104491 and older related patches (D16263, D15766), this seems more straightforward to move accessing the translation code into a utility function instead of making rna_manual_reference.py a place to share utility functions.

This patch will have to be applied to source/tools repo.

diff --git a/utils_doc/rna_manual_reference_updater.py b/utils_doc/rna_manual_reference_updater.py
index 4a8f7f7..d7d494f 100644
--- a/utils_doc/rna_manual_reference_updater.py
+++ b/utils_doc/rna_manual_reference_updater.py
@@ -46,46 +46,17 @@ def write_mappings(inv, output):
     fw(" This file is auto generated from rna_manual_reference_updater.py\n\n")
     # Prevent systems with autopep8 configured from re-formatting the file.
     fw("# autopep8: off\n")
-    fw("import bpy\n\n")
-    fw("manual_version = '%d.%d' % bpy.app.version[:2]\n\n")
-    fw("url_manual_prefix = \"https://docs.blender.org/manual/en/\" + manual_version + \"/\"\n\n")
-    fw("language = bpy.context.preferences.view.language\n")
-    fw("if language == 'DEFAULT':\n")
-    fw("    import os\n")
-    fw("    language = os.getenv('LANG', '').split('.')[0]\n\n")
-    fw("LANG = {\n")
-    fw("\"ar_EG\":        \"ar\",\n")  # Arabic
-    # fw("\"bg_BG\":        \"bg\",\n")  # Bulgarian
-    # fw("\"ca_AD\":        \"ca\",\n")  # Catalan
-    # fw("\"cs_CZ\":        \"cz\",\n")  # Czech
-    fw("\"de_DE\":        \"de\",\n")  # German
-    # fw("\"el_GR\":        \"el\",\n")  # Greek
-    fw("\"es\":           \"es\",\n")  # Spanish
-    fw("\"fi_FI\":        \"fi\",\n")  # Finnish
-    fw("\"fr_FR\":        \"fr\",\n")  # French
-    fw("\"id_ID\":        \"id\",\n")  # Indonesian
-    fw("\"it_IT\":        \"it\",\n")  # Italian
-    fw("\"ja_JP\":        \"ja\",\n")  # Japanese
-    fw("\"ko_KR\":        \"ko\",\n")  # Korean
-    # fw("\"nb\":           \"nb\",\n")  # Norwegian
-    # fw("\"nl_NL\":        \"nl\",\n")  # Dutch
-    # fw("\"pl_PL\":        \"pl\",\n")  # Polish
-    fw("\"pt_PT\":        \"pt\",\n")  # Portuguese
-    # Portuguese - Brazil, for until we have a pt_BR version
-    fw("\"pt_BR\":        \"pt\",\n")
-    fw("\"ru_RU\":        \"ru\",\n")  # Russian
-    fw("\"sk_SK\":        \"sk\",\n")  # Slovak
-    # fw("\"sl\":           \"sl\",\n")  # Slovenian
-    fw("\"sr_RS\":        \"sr\",\n")  # Serbian
-    # fw("\"sv_SE\":        \"sv\",\n")  # Swedish
-    # fw("\"tr_TR\":        \"th\",\n")  # Thai
-    fw("\"uk_UA\":        \"uk\",\n")  # Ukrainian
-    fw("\"vi_VN\":        \"vi\",\n")  # Vietnamese
-    fw("\"zh_CN\":        \"zh-hans\",\n")  # Simplified Chinese
-    fw("\"zh_TW\":        \"zh-hant\",\n")  # Traditional Chinese
-    fw("}.get(language)\n\n")
-    fw("if LANG is not None:\n")
-    fw("    url_manual_prefix = url_manual_prefix.replace(\"manual/en\", \"manual/\" + LANG)\n\n")
+
+    fw(
+        "import bpy\n"
+        "\n"
+        "url_manual_prefix = \"https://docs.blender.org/manual/%s/%d.%d/\" % (\n"
+        "   bpy.utils.manual_language_code(),\n"
+        "   *bpy.app.version[:2],\n"
+        ")\n"
+        "\n"
+    )
+
     fw("url_manual_mapping = (\n")
 
     # Logic to manipulate strings from objects.inv

Move the function for getting the language code associated with the user manual into a utility function (from the generated rna_manual_reference.py). Use this for all user manual URL references. --- After checking on !104491 and older related patches (D16263, D15766), this seems more straightforward to move accessing the translation code into a utility function instead of making `rna_manual_reference.py` a place to share utility functions. This patch will have to be applied to `source/tools` repo. ```.diff diff --git a/utils_doc/rna_manual_reference_updater.py b/utils_doc/rna_manual_reference_updater.py index 4a8f7f7..d7d494f 100644 --- a/utils_doc/rna_manual_reference_updater.py +++ b/utils_doc/rna_manual_reference_updater.py @@ -46,46 +46,17 @@ def write_mappings(inv, output): fw(" This file is auto generated from rna_manual_reference_updater.py\n\n") # Prevent systems with autopep8 configured from re-formatting the file. fw("# autopep8: off\n") - fw("import bpy\n\n") - fw("manual_version = '%d.%d' % bpy.app.version[:2]\n\n") - fw("url_manual_prefix = \"https://docs.blender.org/manual/en/\" + manual_version + \"/\"\n\n") - fw("language = bpy.context.preferences.view.language\n") - fw("if language == 'DEFAULT':\n") - fw(" import os\n") - fw(" language = os.getenv('LANG', '').split('.')[0]\n\n") - fw("LANG = {\n") - fw("\"ar_EG\": \"ar\",\n") # Arabic - # fw("\"bg_BG\": \"bg\",\n") # Bulgarian - # fw("\"ca_AD\": \"ca\",\n") # Catalan - # fw("\"cs_CZ\": \"cz\",\n") # Czech - fw("\"de_DE\": \"de\",\n") # German - # fw("\"el_GR\": \"el\",\n") # Greek - fw("\"es\": \"es\",\n") # Spanish - fw("\"fi_FI\": \"fi\",\n") # Finnish - fw("\"fr_FR\": \"fr\",\n") # French - fw("\"id_ID\": \"id\",\n") # Indonesian - fw("\"it_IT\": \"it\",\n") # Italian - fw("\"ja_JP\": \"ja\",\n") # Japanese - fw("\"ko_KR\": \"ko\",\n") # Korean - # fw("\"nb\": \"nb\",\n") # Norwegian - # fw("\"nl_NL\": \"nl\",\n") # Dutch - # fw("\"pl_PL\": \"pl\",\n") # Polish - fw("\"pt_PT\": \"pt\",\n") # Portuguese - # Portuguese - Brazil, for until we have a pt_BR version - fw("\"pt_BR\": \"pt\",\n") - fw("\"ru_RU\": \"ru\",\n") # Russian - fw("\"sk_SK\": \"sk\",\n") # Slovak - # fw("\"sl\": \"sl\",\n") # Slovenian - fw("\"sr_RS\": \"sr\",\n") # Serbian - # fw("\"sv_SE\": \"sv\",\n") # Swedish - # fw("\"tr_TR\": \"th\",\n") # Thai - fw("\"uk_UA\": \"uk\",\n") # Ukrainian - fw("\"vi_VN\": \"vi\",\n") # Vietnamese - fw("\"zh_CN\": \"zh-hans\",\n") # Simplified Chinese - fw("\"zh_TW\": \"zh-hant\",\n") # Traditional Chinese - fw("}.get(language)\n\n") - fw("if LANG is not None:\n") - fw(" url_manual_prefix = url_manual_prefix.replace(\"manual/en\", \"manual/\" + LANG)\n\n") + + fw( + "import bpy\n" + "\n" + "url_manual_prefix = \"https://docs.blender.org/manual/%s/%d.%d/\" % (\n" + " bpy.utils.manual_language_code(),\n" + " *bpy.app.version[:2],\n" + ")\n" + "\n" + ) + fw("url_manual_mapping = (\n") # Logic to manipulate strings from objects.inv ```
Campbell Barton requested review from Damien Picard 2023-02-09 05:28:19 +01:00
Campbell Barton requested review from Aaron Carlisle 2023-02-09 05:28:20 +01:00
Campbell Barton force-pushed pr-pyapi-manual-fn from 77792c4c30 to 9cf97ddae4 2023-02-09 05:29:48 +01:00 Compare
Campbell Barton force-pushed pr-pyapi-manual-fn from 9cf97ddae4 to 3902b422cb 2023-02-09 05:31:34 +01:00 Compare
Damien Picard approved these changes 2023-02-09 19:32:41 +01:00
Damien Picard left a comment
Member

Yes, this is perfect! Thanks

Yes, this is perfect! Thanks
Author
Owner

Committed, closing.

Committed, closing.
Campbell Barton closed this pull request 2023-02-10 01:38:23 +01:00
Campbell Barton deleted branch pr-pyapi-manual-fn 2023-02-10 01:39:20 +01:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
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: blender/blender#104494
No description provided.