Skip to content

Bugfixes in preparation for switching to Weblate for translations#635

Merged
freakboy3742 merged 8 commits intobeeware:lektorfrom
kattni:weblate
May 27, 2025
Merged

Bugfixes in preparation for switching to Weblate for translations#635
freakboy3742 merged 8 commits intobeeware:lektorfrom
kattni:weblate

Conversation

@kattni
Copy link
Copy Markdown
Contributor

@kattni kattni commented May 27, 2025

This is the first step towards switching the website to Weblate for translations.

As discussed, I have updated the data models to indicate what fields should be translated. I also added a fix to the plugin itself to handle the duplicate message definition error, as the workaround we talked about addressed two out of what turned out to be a significant number of instances of this issue.

I need the following two things from @freakboy3742 at this point:

  • Verify that I have added translate = True to all applicable fields in the model files. These files are in the flowblocks and models directories. There may be one or two empty ones that I left out in my initial attempt to deal with the above-mentioned error, and I feel at this point that they should be included, so please be aware of that as you go through this.
  • Please tell me if this is a reasonable fix. I added if msg: to this block. My intention here is to skip generating any sections in the .pot file if there is no content in a given field, to avoid the above-mentioned error. It appears to be working, but I don't understand this enough to really grasp the implications of the change, so I would appreciate your input on it.

Fixes #634

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@kattni kattni marked this pull request as draft May 27, 2025 02:58
Comment on lines +120 to +127
for msg, paths in self.translations.items():
if msg:
result += "#: %s\n" % " ".join(paths)
for token, repl in {'\\': '\\\\', '\n': '\\n', '\t': '\\t', '"': '\\"'}.items():
msg = msg.replace(token, repl)
result += 'msgid "%s"\n' % msg
result += 'msgstr ""\n\n'
return result
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@freakboy3742 I added the if msg: to this block, as described in the initial PR comment. Tagging it here for more convenient reference.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Re Q1: I've flagged a couple of possible omissions in the translation markup.

I wonder if we might want to remove some translations as well. Is it reasonable for translators to keep up with blog posts? Event updates? I'm mostly wary that the PO file is 18k lines long, and because it's all one file, there's no good way to prioritise what is "important" content vs less important.

Re Q2: As far as I can make out, the if msg: change makes sense. The only potential risk I can see is on the "reverse" approach - if the code that tries to process the translation does a lookup of "", and doesn't find a match, does it raise an error? Based on my testing, it doesn't look like it does... so maybe that is success?

Comment thread models/blog-post.ini Outdated
label = Author
type = string
width = 1/2
translate = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does the author name need to be translated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No. I'm not sure why I flagged it. Will remove.

Comment thread flowblocks/text-block.ini
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Presumably flowblocks/button-block.ini also has some translation opportunities in the button label?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, right. Yes most likely. As I said, I'm not as familiar with the flowblocks. I wasn't thinking about it.

Comment thread models/project.ini
Comment thread packages/lektor_i18n_plugin/README.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if this is the Tor version or the original (it looks like the original), but we should put a note at the top here describing the provenance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It should be the Tor version. I will add this.

Comment thread packages/lektor_i18n_plugin/README Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to include both of these; as long as we retain the license and describe provenance, we don't have to preserve all the content.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll keep this in mind for the next PR. This PR will ultimately not have the plugin in it yet.

@kattni
Copy link
Copy Markdown
Contributor Author

kattni commented May 27, 2025

I looked through the Tor updates. Only one of them has any details beyond the commit title. It appears to resolve the multiple-build issue. Here is what I found:

this moves the compilation of .po files and translation of contents.lr files earlier in the build process, in on_before_build_all instead of on_before_build, to ensure that the build queue accounts for the alternative content files (contents+*.lr) during the build process, instead of requiring multiple (expensive) build runs

the caveat is that translated alternative contents files are now only produced during a full build, which likely breaks "on-the-fly" creation of those files when authoring using the Lektor web admin interface

I am including this here because I don't quite know the implications of the caveat, and I wanted to make sure you were aware as it probably makes more sense to you than me.

Regarding your comments:

I wonder if we might want to remove some translations as well. Is it reasonable for translators to keep up with blog posts? Event updates? I'm mostly wary that the PO file is 18k lines long, and because it's all one file, there's no good way to prioritise what is "important" content vs less important.

I am inclined to agree with this. I initially assumed that there was a lot of consistency across the event updates, which if you base it on the last few tutorials, it's not an incorrect assumption, but looking through the .po file as a whole, this appears to not be the case. We can always add this back in if we get the whole site translated and people are looking for more.

Re Q2: As far as I can make out, the if msg: change makes sense. The only potential risk I can see is on the "reverse" approach - if the code that tries to process the translation does a lookup of "", and doesn't find a match, does it raise an error? Based on my testing, it doesn't look like it does... so maybe that is success?

I'll take maybe for an answer. Obviously if it eventually chokes, we can revisit it.

@freakboy3742
Copy link
Copy Markdown
Member

I am including this here because I don't quite know the implications of the caveat, and I wanted to make sure you were aware as it probably makes more sense to you than me.

I won't profess enough experience with Lektor to fully understand all the consequence of such a change - but it sounds to me like this is a fix for the 'needs 2 builds' problem you've been seeing. Definitely something worth keeping an eye on, though.

@kattni
Copy link
Copy Markdown
Contributor Author

kattni commented May 27, 2025

@freakboy3742 Ok, here are the updates:

  • I fixed the bugs in the couple of Resources links we found, specifically the lack of titles on the two latest ones, and the space in the directory name. I also updated the missed rST link to be Markdown.
  • I removed the translate tag from the blog posts and the individual events - I left them on the "main" page models. I believe that means it only applies to the "index" for each of them, but let me know if I'm missing something with this.
  • I updated the previously-missed /contributing/membership/ link to /membership/. I believe I verified this was a complete change, but please let me know if I missed anything - I was struggling within Git to deal with all the files generated and modified by the plugin, so I may have accidentally dropped one of the changes.
  • I removed the plugin and the related-config files for the purposes of this PR.

I think this is ready for another look.

@kattni
Copy link
Copy Markdown
Contributor Author

kattni commented May 27, 2025

I won't profess enough experience with Lektor to fully understand all the consequence of such a change - but it sounds to me like this is a fix for the 'needs 2 builds' problem you've been seeing. Definitely something worth keeping an eye on, though.

Understood. That is my take on it as well, however I wanted to ensure you were aware of it in case it ends up affecting our implementation.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

tl;dr - this looks like a completely uncontroversial set of changes. There's likely more work that could be done to improve the pagination even more (what even is the gutter for on those pages?...) - and the translation flags obviously won't do anything yet, other than indicate that things could be translated - but I'd be happy landing this set of changes as is.

@kattni kattni changed the title WIP: Switch to Weblate for translations Bugfixes in preparation for switching to Weblate for translations May 27, 2025
@kattni kattni marked this pull request as ready for review May 27, 2025 23:34
@kattni
Copy link
Copy Markdown
Contributor Author

kattni commented May 27, 2025

@freakboy3742 Updated title, no longer draft status.

@kattni kattni requested a review from freakboy3742 May 27, 2025 23:38
Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 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 - and one step closer to managed translations!

@freakboy3742 freakboy3742 added the preview Approved for an automated preview label May 27, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Visit the preview URL for this PR (updated for commit 46967a9):

https://beeware-org--pr635-weblate-5eia3r6c.web.app

(expires Tue, 03 Jun 2025 23:47:54 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b0da44bc067e7d9a4255c77cb2c5fce572218cec

@kattni
Copy link
Copy Markdown
Contributor Author

kattni commented May 27, 2025

(what even is the gutter for on those pages?...)

I would also love to know the answer to this. I guess we'll have to ask the person who wrote it?

...the translation flags obviously won't do anything yet, other than indicate that things could be translated...

I verified this before submitting this as-is. They are ignored without the plugin.

@freakboy3742
Copy link
Copy Markdown
Member

(what even is the gutter for on those pages?...)

I would also love to know the answer to this. I guess we'll have to ask the person who wrote it?

Nah - that guy doesn't know anything... 🤣

...the translation flags obviously won't do anything yet, other than indicate that things could be translated...

I verified this before submitting this as-is. They are ignored without the plugin.

👍

@freakboy3742 freakboy3742 merged commit 51c6a63 into beeware:lektor May 27, 2025
2 checks passed
@johnzhou721
Copy link
Copy Markdown
Contributor

I wonder if we might want to remove some translations as well. Is it reasonable for translators to keep up with blog posts? Event updates? I'm mostly wary that the PO file is 18k lines long, and because it's all one file, there's no good way to prioritise what is "important" content vs less important.

I'd definitely be interested to translate the blog posts, event updates etc, once I have more time.

Since we're maintaining the letkor-i18n-plugin, we could add code that splits those into another file (=component on Weblate) and sort them according to the date published that is listed in the lektor source file. When we're merging a little bit more work is needed because AFIAK there's no way for msgmerge to specify a custom sort key. So it'd involve loading the merged unsorted file and resorting it and saving it.

Do you think this would be a good way?

@freakboy3742
Copy link
Copy Markdown
Member

I wonder if we might want to remove some translations as well. Is it reasonable for translators to keep up with blog posts? Event updates? I'm mostly wary that the PO file is 18k lines long, and because it's all one file, there's no good way to prioritise what is "important" content vs less important.

I'd definitely be interested to translate the blog posts, event updates etc, once I have more time.

You're one person, translating one language. I'm very wary of setting up a bunch of complex infrastructure to support one contributor on one language, and thereby setting up expectations for other languages, unless we've got evidence that blog posts will be translated regularly.

Since we're maintaining the letkor-i18n-plugin, we could add code that splits those into another file (=component on Weblate) and sort them according to the date published that is listed in the lektor source file. When we're merging a little bit more work is needed because AFIAK there's no way for msgmerge to specify a custom sort key. So it'd involve loading the merged unsorted file and resorting it and saving it.

Do you think this would be a good way?

Is it possible? Maybe. Is it worth it? I doubt it, for the same reason that we omitted blog posts in the first place.

@johnzhou721
Copy link
Copy Markdown
Contributor

I agree with you on the first part and intended the second part to be a totally theoretical discussion… There’s some regular work in Spanish going on, but there’s nothing in the other langs so far… it’d make sense for a lot of people to be working on website translations for this to be worth it/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Approved for an automated preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to Weblate for translations

3 participants