-
Notifications
You must be signed in to change notification settings - Fork 1.5k
i18n: Localize Nautilus .py script #9976
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
base: main
Are you sure you want to change the base?
Conversation
swsnr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a member of the ghostty project, so please excuse me for leaving a review, but as the original author of this script (albeit for Wezterm originally), and being somewhat familiar with xgettext and Python, I'd like to leave two remarks concerning this pull request 🙂
dist/linux/ghostty_nautilus.py
Outdated
| import gettext | ||
|
|
||
| DOMAIN = "com.mitchellh.ghostty" | ||
| share_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be more readable with pathlib:
from pathlib import Path
locale_dir = Path(__file__).absolute().parent.parent.parent / "locale"And does the Ghostty build system even guarantee that the locales always end up at this path, relative to the nautilus extension directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that you can use .parents[2] instead of .parent.parent.parent =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trag1c Oh, thanks 🙏 I learn a new thing every day 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swsnr As far as I can see, the nautilus extension is here
GhosttyResources
try steps.append(b.allocator, &b.addInstallFile(
b.path("dist/linux/ghostty_nautilus.py"),
"share/nautilus-python/extensions/ghostty.py",
).step);
and the locale is relative to share so share/locale/....
During the build process, each locale in `.po` files is compiled
into binary `.mo` files, stored under `share/locale/<LOCALE>/LC_MESSAGES/com.mitchellh.ghostty.mo`.
This can be directly accessed by `libintl`, which provide the various `gettext`
....
The only issue is what I mentioned in the original comment where some other platforms put the locale with a different suffix and then it doesnt work, so it just fallbacks.
src/build/GhosttyI18n.zig
Outdated
| "-", | ||
| }); | ||
| // Silences the "unknown extension" errors | ||
| _ = xgettext.captureStdErr(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that that's a good idea.
I believe the proper way to handle different types of sources with different flags in xgettext is to use separate xgettext invocations to extract messages into intermediate pot files, and then use a final xgettext invocation to merge the intermediate pot files into the final one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah thanks, I have edited it now. Much cleaner this way.
|
@swsnr Even though it seems you are not an official maintainer, I saw emoji reactions by at least a maintainer, so I assume these changes were approved as well from them. I made those changes, lmk and thanks for the review! |
Closes #9266.
Big Note: I noticed that this worked properly under
NixOS, but on myUbuntuVM it didnt.The reason is in src/build/GhosttyI18n.zig because the locale is expected in the
<lang>_<region>without the encoding suffix.<lang>_<region>_<encoding>If i force it to always trim the encoding it works, but I am guessing its there for a reason ,so maybe some of the maintainer can shed some light in the best way forward, as I am not an expert in how other systems deal with it. Here you see
Open in Ghostty-> Abrir con Ghosttypyfile withruffbut didnt want to drown the changes, so maybe something that could be worth doing so that also ourpyfiles have std formatting.Note
Used AI only for helping me debug where the locales could be and why was it not detected, but no code help whatsoever