YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.22k stars 403 forks source link

Language pack is constantly updated #494

Closed paeddy-l closed 2 years ago

paeddy-l commented 2 years ago

Hello,

I use the self-hosted variant of the update checker for one of my plugins. The updates of the plugin work without problems. What causes problems are updates from the language packs. I have created the language files in the folder of the plugin under "languages". If I now enter the following in the .json:

{
    "name": "Plugin Name",
    "slug": "plugin_slug",
    "version": "0.4.2",
    "download_url": "https://example.com/download.zip",
    "homepage": "",
    "requires": "",
    "tested": "6.0",
    "requires_php": "5.6.4",
    "author": "Paeddy",
    "author_homepage": "Author URL",
    "last_updated": "2022-06-04 16:30:00 +0200",
    "upgrade_notice": "",
    "banners": "",
    "icons": {
         "1x": "https://example.com/img/icon-128x128.png",
         "2x": "https://example.com/img/icon-256x256.png"
     },
     "translations": [{
      "language": "de_DE",
      "version": "1.0",
      "updated": "2022-06-06 13:10:00",
      "package": "https://example.com/downloads/german-language.zip"
    }],
    "sections": {
        "description": "Description of the plugin..."
    }
}

the language files are stored under "/wp-content/languages/plugins". In itself no problem, as it works just as well. Now to the problem: When I deploy a new version of the language packs, WordPress recognizes this and updates them as well, however WordPress wants to download the language packs again every few minutes afterwards. What am I doing wrong? I hope I could formulate my concern precisely. If something is unclear, please let me know. Thank you very much.

Kind regards

YahnisElsts commented 2 years ago

When you say "every few minutes", do you mean that the language pack update shows up again immediately, or is there actually some short time period where you can reload the update page and not get the same update?

An update showing up again immediately might indicate that there's some kind of a bug in the code that clears the update list. On the other hand, if there's a delay - even a small one - that suggests there could be something wrong with the update itself, like an incorrect PO-Revision-Date header.

paeddy-l commented 2 years ago

I mean that it is displayed again a few minutes after a successful update. Not immediately, but a few minutes later. I have created the translation with Poedit. Unfortunately I don't see anywhere a possibility to store a concrete version for the translation or something similar. I just create the files, pack both (.mo and .po) as .zip and make them available for download. This then results in the problem I described. What am I doing wrong? For this, the newly downloaded translation is placed under /wp-content/languages/plugins and not, as I had hoped, under /wp-content/plugins/{Plugin_Name}/languages. Is that the way it's meant to be by default, or is there a way to change it?

YahnisElsts commented 2 years ago

As far as I know, WordPress doesn't use version numbers for language packs. The last time I checked, the API had a version field, but WordPress core didn't actually do anything with that field.

Since there are no usable version numbers, PUC uses timestamps instead. It will present a language pack as an update if the updated timestamp in the JSON metadata is greater than the PO-Revision-Date timestamp in the installed translation. You can find this timestamp by opening a .po file in any text editor. You will probably see a line like this near the top of the file:

"PO-Revision-Date: 2022-06-12 12:34:56+0000\n"

For language pack updates to work correctly, the updated timestamp should match (or exceed) this value. Maybe like this:

"updated": "2022-06-12 12:34:56+0000"

For this, the newly downloaded translation is placed under /wp-content/languages/plugins and not, as I had hoped, under /wp-content/plugins/{Plugin_Name}/languages. Is that the way it's meant to be by default, or is there a way to change it?

Yes, I think that's the default. Anyway, the update checker doesn't control the install location, WordPress core is what actually installs the updates.

If you want translations to be installed only as part of the plugin, maybe you don't need this feature at all? You could just leave out the translations section, keep translations in your languages subdirectory, and load them explicitly with load_plugin_textdomain.

paeddy-l commented 2 years ago

Thanks for the explanation. I think it's easiest if I remove the translationssection as you suggested and provide the translations directly with updates to the plugin. That way I have less work and it's all done with one deployment.

Thanks a lot for this great project.

YahnisElsts commented 2 years ago

Sounds good. I'll close this now.