Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More graceful translations startup handling #630

Merged
merged 8 commits into from
Aug 25, 2024

Conversation

TheDuckCow
Copy link
Member

@TheDuckCow TheDuckCow commented Aug 24, 2024

Closes #627 hopefully for real.

Was to fix this error that was seen on install/startup with the initial v3.6.1.1 release which has now been pulled:

Traceback (most recent call last):
  File "/Applications/Blender 4.3/blender.app/Contents/Resources/4.3/scripts/modules/addon_utils.py", line 407, in enable
    mod = importlib.import_module(module_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/Blender 4.3/blender.app/Contents/Resources/4.3/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/__init__.py", line 59, in <module>
    from . import load_modules
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/load_modules.py", line 118, in <module>
    from . import mcprep_ui
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/mcprep_ui.py", line 106, in <module>
    class MCPREP_MT_mob_spawner(bpy.types.Menu):
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/mcprep_ui.py", line 108, in MCPREP_MT_mob_spawner
    bl_label = env._("Mob Spawner")
               ^^^^^^^^^^^^^^^^^^^^
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/conf.py", line 166, in _
    if bpy.context.preferences.view.language in self.languages:
                                                ^^^^^^^^^^^^^^
AttributeError: 'MCprepEnv' object has no attribute 'languages'

Working on another patch for you to review.

@TheDuckCow TheDuckCow linked an issue Aug 24, 2024 that may be closed by this pull request
2 tasks
@TheDuckCow TheDuckCow marked this pull request as draft August 24, 2024 06:33
@TheDuckCow
Copy link
Member Author

It's late, and this is still causing startup errors now. Now I'm getting errors like:

  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/conf.py", line 166, in _
    return self.languages["en_US"].gettext(msg)
           ~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'en_US'
Error: 'en_US'

@StandingPadAnimations need your input here, since you're more familiar with the translation startup sequence. Whatever fix we try, we should please try to do an install over a previously prod v3.6.0 release to sanity check it's working, that's where I keep hitting a wall. You have my permission to take over this branch if you have ideas of a more suitable fix.

In general, I do think it's not ideal to only conditionally define a property to exist, which was the reason for the original bug above. I'm also not sure why it's in the branch where content isn't loaded, since I've confirmed my local build's zip does indeed contain the .mo and .po files for each of the languages above.

@TheDuckCow
Copy link
Member Author

FYI I think I have a decent fix locally, will push in a bit. Doing some testing

Comment on lines +92 to +95
self.assertTrue(
os.path.isfile(
lang_folder / lang / "LC_MESSAGES" / "mcprep.mo"),
f"Missing {lang}'s mo file")
Copy link
Member Author

Choose a reason for hiding this comment

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

If nothing else, we could reduce the test down to just this, which already goes a long way to prove that translations are present when they should be.

Likewise made the gitignore a little more strict for what we want
@TheDuckCow TheDuckCow marked this pull request as ready for review August 25, 2024 01:39
Copy link
Member Author

@TheDuckCow TheDuckCow left a comment

Choose a reason for hiding this comment

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

That was a doozy, one thing after another - but, we're there. All local tests pass, as do the ones on github actions above thankfully

-------------------------------------------------------------------------------
bversion   	ran_tests	ran	skips	failed	errors
-------------------------------------------------------------------------------
(4.2.0)   	all_tests	70	2	0	No errors
(4.0.2)   	all_tests	70	2	0	No errors
(3.6.2)   	all_tests	70	2	0	No errors
(3.5.1)   	all_tests	70	2	0	No errors
(3.4.0)   	all_tests	70	2	0	No errors
(3.3.1)   	all_tests	70	2	0	No errors
(3.2.1)   	all_tests	70	2	0	No errors
(3.1.0)   	all_tests	70	2	0	No errors
(3.0.0)   	all_tests	70	2	0	No errors
(2.93.0)   	all_tests	69	3	0	No errors
(2.90.1)   	all_tests	69	3	0	No errors
(2.80.75)   	all_tests	68	4	0	No errors
Compiled in 30.6s + tests ran in 269.9s
Total of 300.5s with exit code 0

test_translations = [
("ru_RU", "Restart blender", "Перезапустите блендер"),
# Blender 4.0+ only has 'zh_HANS', 'zh_HANT'
("zh_HANS" if bpy.app.version > (4, 0) else "zh_CN", "Texture pack folder", "材质包文件夹"),
Copy link
Member Author

Choose a reason for hiding this comment

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

Explanation here, and also why I've added a new PO file (simplest option I could think of without further consequences/code changes)

Thanks to this test, I discovered we weren't supporting Chinese pre 4.0 due to Blender splitting into more sub regional names. The enum key zh_HANT only exists as os 4.0 (thus this test was failing pre blender 4.0), and meanwhile zh_CN only exists before. I understand from some reading that zh_HANT is more regional version of simplified Chinese, so I feel it's appropriate as a stopgap for now.

@@ -19,5 +19,12 @@ venv/
*.sublime-*
MCprep_addon/import_bridge/conf
MCprep_addon/import_bridge/nbt
MCprep_addon/MCprep_resources/
MCprep_addon/MCprep_resources/*.blend
Copy link
Member Author

Choose a reason for hiding this comment

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

Before this change, we were masking .po files, felt it was worth making sure we had it recognized explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

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

An as-is copy of the zh_HANS.

I live-tested in both blender 3.x and 4.x to make sure that translations work fine in both cases (I'd say, it feels odd that the translations actually were working in blender 4.0 before since the contents of the po reference zh_CN and not zh_HANS, but I'm not going to dive into understanding that right now)

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're curious, zn_CN is the old code for Simplified Chinese. It was changed to zn_HANS since many countries outside of China also use Simplified Chinese (at least that's what I was able to gather when I looked into it a while back)

Copy link
Collaborator

@StandingPadAnimations StandingPadAnimations left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just a minor stylistic nitpick

MCprep_addon/conf.py Outdated Show resolved Hide resolved
@TheDuckCow TheDuckCow merged commit d4d0dd3 into dev Aug 25, 2024
1 check passed
@TheDuckCow TheDuckCow deleted the 627-more-graceful-handling branch August 25, 2024 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MCprep 3.6.1 Update is Missing Compiled Translations
2 participants