Giter VIP home page Giter VIP logo

traduttore's Introduction

Traduttore

PHPUnit Lint codecov Latest Stable Version Latest Unstable Version

Traduttore is a WordPress plugin that allows you to host your own WordPress.org-style translation API for your WordPress projects.

How it Works

Working on a multilingual WordPress project with custom plugins and themes can be quite cumbersome. Every time you add new strings to the project, you have to regenerate POT files and update the PO/MO files for every locale. All these changes clutter the history of your Git repository and are prone to errors as well. Plus, you can't easily send these translation files to your clients.

These problems don't exist for plugins and themes hosted on WordPress.org, as they benefit from the translate.wordpress.org translation platform. Whenever you publish a new version of your project, WordPress.org makes sure that new strings can be translated. With Traduttore, you can now get the same experience for your custom projects hosted on GitHub!

Every time you commit something to your plugin or theme, Traduttore will extract translatable strings using WP-CLI and add import these to GlotPress.

Then, you (or even your clients!) can translate these strings right from within GlotPress. Whenever translations are edited, Traduttore will create a ZIP file containing PO and MO files that can be consumed by WordPress. A list of available ZIP files is exposed over a simple API endpoint that is understood by WordPress.

Using our little helper library called Traduttore Registry, you can then tell WordPress that translations for your project should be loaded from that API endpoint.

After that, you never have to worry about the translation workflow ever again!

Features

  • Automatic string extraction
  • ZIP file generation and caching
  • Works with any WordPress plugin or theme hosted on GitHub
  • Custom WP-CLI commands to manage translations
  • Supports Restricted Site Access
  • Supports sending Slack notifications

a required open source product - let's get in touch

traduttore's People

Contributors

dependabot[bot] avatar florianbrinkmann avatar florianziegler avatar grappler avatar krokodok avatar ocean90 avatar pedro-mendonca avatar swissspidy avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

traduttore's Issues

Use more unique temp folder for Traduttore

Just so there aren't any conflicts when there are multiple Traduttore installs on a server.

Code in question:

/**
* Returns the path to where the Git repository should be checked out.
*
* @since 3.0.0
*
* @return string Git repository path.
*/
public function get_local_path() : string {
return sprintf(
'%1$s-traduttore-%2$s-%3$s',
get_temp_dir(),
$this->repository->get_host(),
$this->repository->get_slug()
);
}

Add some docs for troubleshooting

Related: #67

We should some general docs for troubleshooting / FAQs for people to help debug common issues.

Examples:

  • why no translations have been updated
  • why no zip file has been built
  • debug string extraction issues
  • test WP-CLI availability
  • test git configuration and repository access
  • test configuration of a project (i.e. is the repository url correct and the repository reachable)

Reduce the time when the ZIP file is created

I think we should reduce the time when teh ZIP file is created.

wp_schedule_single_event( time() + MINUTE_IN_SECONDS * 15, 'traduttore_generate_zip', [ $translation->translation_set_id ] );

As it is a one time event it should be Ok to run near instantaneous.

My recommendation would be to reduce it to 5 minutes from 15 minutes.

Make cron event times filterable

In #3 the time we wait until the next ZIP file generation has been reduced to 5 minutes.

I get it that one doesn't want to wait 15 minutes all the time, but when lots of translations are happening, it gets noisy quickly:

screenshot 2018-10-24 at 10 34 51

Can we somehow prevent this by throttling notifications or changing the time again? For the latter I suggest making them filterable. Both for the incoming webhook event as well as the language pack generation.

Add webhook support for Bitbucket and GitLab

Although the plugin now theoretically supports fetching projects from Bitbucket and GitLab.com, we don't support receiving webhooks from these providers just yet.

Without that support, the plugin isn't that useful when on these platforms.

Right now we add a custom github-webhook/v1/push-event REST route for consuming incoming GitHub webhooks. This has two big disadvantages:

  • The name is not really uniquely namespaced.
  • The REST callback is very GitHub-specific, e.g. by checking for X-GitHub-Event headers and assuming a certain data structure.

Possible solutions:

  • Add a new traduttore/v1/<provider>-incoming REST route for each provider. Examples:
    • traduttore/v1/github-incoming
    • traduttore/v1/bitbucket-incoming
    • traduttore/v1/gitlab-incoming
    • traduttore/v1/custom-incoming (common route for custom repositories with filterable callback)
  • Deprecate github-webhook/v1/push-event in favor of traduttore/v1/github-incoming
    Migration might be easier with something like #55
  • Alternatively: use only one REST route, e.g. traduttore/v1/incoming-webhook and choose correct handler depending on source. This could be a separate class per source.
    The question here would be how the source could be detected in a reliable matter.

Bitbucket documentation:

https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html
https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html

GitLab documentation:

https://docs.gitlab.com/ee/user/project/integrations/webhooks.html

Allow storing sync secrets per project

Defining these secrets in wp-config.php means you can't easily use this with Multisite or with multiple self-managed GitLab repositories unless they all share the same secret.

Retrieving the secret could be filterable and we could still fall back to the defined constants there for BC.

Related #57.

Add docs for Git and WP-CLI setup

  • The server running the plugin needs be able to connect to GitHub via SSH and has access to the requested repos.
  • For the POT generation, WP-CLI with the i18n-command is required.
  • TRADUTTORE_WP_BIN can be used to customize the path of WP-CLI bin.

Notify about warnings from make-pot command

When running wp i18n make-pot, the script notifies you when an extracted string has two or more different translator comments.

See https://github.com/wp-cli/i18n-command/blob/7e11d8c2ead4787997c41fb77809f7c90ef787ca/src/MakePotCommand.php#L315-L321 and https://github.com/wp-cli/i18n-command/blob/7e11d8c2ead4787997c41fb77809f7c90ef787ca/features/makepot.feature#L528-L556.

This is usually a sign of a developer mistake, as the string would only be imported once in GlotPress, but have 2 comments added to it.

Here's an (over simplified) example:

/* translators: Translators 1! */
sprintf( __( 'Hello World', 'foo-plugin' );

/* Translators: Translators 2! */
__( 'Hello World', 'foo-plugin' );

What if Traduttore would send a Slack notification when such a warning is encountered? (*)

The same goes for other warnings:

  • Files that can't be opened
  • Files that can't be parsed and need to be reviewed and perhaps excluded
  • The command fails for another reason and exits with a non-zero status

(*) Now that I think about it, this could also work as a HM Linter integration 🤯

Initial import when adding a new project

It would be very convenient to import translations for a newly added project without having to manually run wp traduttore update or waiting for the next commit.

Perhaps by adding a single cron event when saving a project or by adding a button to the UI.

Add option to create POT file without updating the Git repo

For the times where you know the cached repository is up-to-date so you don't want to unnecessarily run git reset and git pull, just good old wp i18n make-pot on it.

This could be done by adding a --cached flag to UpdateCommand and passing that as an argument to \Required\Traduttore\Runner::run(). In that case that method would simply call \Required\Traduttore\Loader::get_local_path() instead of \Required\Traduttore\Loader::download().

And if \Required\Traduttore\Loader::get_local_path() returns null you know a cached repository doesn't exist and can throw an error in the terminal accordingly.

Separate customizations from API

I kinda hijacked the existing Traduttore plugin for #1 and #2.

Previously it only handled some customizations for translate.required.com. Now it does a whole lot more.

If we want to open source our solution (the blog post is ready) and easy to set up for others, it would make sense to keep the site customizations and the import / ZIP generation / API parts in two (or more?) separate projects.

Thoughts?

Integrate with other Slack Notification plugin

For #48 we need some more powerful Slack notifications. At least attachments would be helpful. And buttons. And unicorns.

We currently support https://wordpress.org/plugins/slack/, however that plugin is a bit limited in terms of available formatting and hasn't been updated in quite some time.

https://wordpress.org/plugins/dorzki-notifications-to-slack/ looks like a promising alternative.

For the time being we could support both, with the new one being the preferred solution for some more powerful Slack notifications.

Integrations seems to be pretty straightforward, see https://github.com/wearerequired/required-jobboard/pull/12 and https://github.com/dorzki/Slack-Notifications

Traduttore as a Service (TaaS)

After successfully giving a talk about WordPress I18N Workflows, telling everyone how great Traduttore is. I even promoted it as "WordPress.org for everyone". After that, I wondered: how can we make this statement really true? How can we make it easier for people to use this?

Setting up Traduttore requires quite some technical knowledge, so I doubt many people or agencies will use it out of the box. There's only so much we can do with better documentation and UI changes either.

What if we built some simple Multisite solution where everyone can create their own Traduttore instance, connecting their private plugins and using this platform to translate them?

It would truly be (translate.)WordPress.org for everyone. Kinda what platforms like Transifex & co. do, but really tailored to the WordPress community.

Release 2.0.3

The milestone is almost closed.

Only needs a final review, changelog, tag, and GitHub release.

Release 3.0

To do:

  • Review documentation
  • Update changelog
  • Tag new release
  • Bump branch alias in composer.json

Avoid Slack notifications for imports without changes

When nothing has changes you get the following notification:

Project Name: 0 new strings were added, 0 were fuzzied, and 0 were obsoleted. There were 0 errors

IMO we should suppress such messages in

traduttore/inc/Plugin.php

Lines 112 to 130 in 0e9e7f6

'message' => function( GP_Project $project, array $stats ) {
[
$originals_added,
$originals_existing,
$originals_fuzzied,
$originals_obsoleted,
$originals_error,
] = $stats;
return sprintf(
'<%1$s|%2$s>: *%3$d* new strings were added, *%4$d* were fuzzied, and *%5$d* were obsoleted. There were *%6$d* errors.',
home_url( gp_url_project( $project ) ),
$project->name,
$originals_added,
$originals_fuzzied,
$originals_obsoleted,
$originals_error
);
},
.

Bust WP-CLI translation cache

I updated the translations on translate.required.com but WP-CLI is not downloading the latest version.

wp @stage language core update
Updating 'German' translation for Swisscom Post Types ...
Using cached file '/home/deploy/.wp-cli/cache/translation/plugin-swisscom-content-types--de_DE-1522156473.zip'...
Entpacken der aktualisierten Version …
Die aktuelle Version wird installiert …
Die Übersetzung wurde erfolgreich aktualisiert.
Success: Updated 1/1 translations.

Analyze class structure

Extracted from #70:

We might need to move some stuff around. For example delete_local_repository() might make more sense in the Updater instead of Runner.

Protect route for incoming Bitbucket webhooks

Issue Overview

In #70 we discussed how we can better protected the incoming webhook route for Bitbucket requests.

Bitbucket.org doesn't support secrets, so it's not really possible to verify these requests.

Right now we simply let all requests pass, which is not ideal.

What we could do:

  • Check request headers to verify that the requests come from Bitbucket
    Error prone, doesn't help that much.
  • Disallow these incoming webhooks by default and have users filter the responses to make them work.
    Poor UX because they don't work out of the box.

Additional context
#70

Release version 2.0.2

  • Update changelog
  • Update version in plugin file header
  • Create a new tag
  • Create a new GitHub release

Document available actions/filters

  • traduttore_zip_generated
  • traduttore_updated_from_github
  • #38

Not sure if the readme would be the right place for this. It already has a lot of information. Maybe we should start splitting the file into a /docs directory?

Add CLI command to edit project meta information

Basically like https://github.com/wp-cli/entity-command, but for project meta, I'd want an easy way to set project meta information like VCS type and things like that using WP-CLI.

Not sure how easy it would be to require that command and extend \WP_CLI\CommandWithMeta. Otherwise we'd have to copy the code a bit.

Also, this might be something for GlotPress itself and not specifically Traduttore.

Publish on Packagist

  • Bring readme for Traduttore and Traduttore Registry up to date
  • Link to the other project in each readme
  • Make sure the version numbers are correct
  • Tag a version 1.0.0 for both projects (or 2.0.0?)
  • Maybe add a changelog (or use GitHub releases)
  • Make sure the composer.json files are up to date.
  • Whatever else I forgot

Create GitHub App / Bot / Integration

Advantages:

  • Easier to use
  • No need to manually create webhooks
  • Status updates / progress for GitHub pull requests
  • Inline annotations in pull requests for faulty text strings marked by WP-CLI

Add CLI command for debugging

Some thoughts about possible WP-CLI commands for easier debugging:

wp traduttore info

This could show some status information, e.g. things like:

  • Plugin version
  • Path to git binary
  • Path to WP-CLI binary
  • Path to cache dir
  • Whether requirements (git, WP-CLI i18n-command, zip extension, Slack plugin, etc.) are met
  • …?

wp traduttore debug <project>

  • Repository information (type, vcs type, url, visibility)
  • Path to the cached repository
  • Whether the repository exists and Traduttore has access to it

Add way to remove the checked out Git repository

Background: https://required.slack.com/archives/C4YP8FVB5/p1525731910000044

wp traduttore translations update https://github.com/user/repo/
fatal: Kein Git-Repository (oder irgendein Elternverzeichnis bis zum Einhängepunkt /)
Stoppe bei Dateisystemgrenze (GIT_DISCOVERY_ACROSS_FILESYSTEM nicht gesetzt).
fatal: Kein Git-Repository (oder irgendein Elternverzeichnis bis zum Einhängepunkt /)
Stoppe bei Dateisystemgrenze (GIT_DISCOVERY_ACROSS_FILESYSTEM nicht gesetzt).
Warning: Could not update translations for project (ID: 123)!

Having a command to remove a broken Git repository in /tmp is easier than having to try finding out where that repo is and to delete it via SSH.

rmdir() requires that the directory is empty

GitHubUpdater::remove_local_repository() calls rmdir() but doesn't remove its content first.

Warning: rmdir(/tmp/traduttore-github-foo): Directory not empty in /content/plugins/traduttore/inc/GitHubUpdater.php on line 88

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.