Install&Update wordpress languages with composer

#Wordpress translations as composer packages

Breaking changes in 2016
If you were using: http://languages.koodimonni.fi please change to https://wp-languages.github.io instead.


I fell so much in love with using composer on wordpress that I just hated how there was no good solution to install languages with composer.

Well until I made this custom repository: https://wp-languages.github.io

It uses my composer dropin installer which solves the problems with composer overwriting everything in the same folder.

So now you can extract multiple packages into same folder: web/app/languages

Site is hosted in github pages and uses translation zip-archives from api.wordpress.org. So big thanks for them.

##How to use

There’s 4 types of packages. These examples are for French (fr_FR):

koodimonni-language/fr_FR => All latest language files for French. This includes wordpress-importer,akismet, woocommerce and all twenty-themes (if available for that language). So use this shortcut to automatically include all packages mentioned below.

If you want to be picky you can choose which packages to include by using these examples:

koodimonni-language/core-fr_FR => Just core language packages
koodimonni-plugin-language/akismet-fr_FR => akismet plugin translations
koodimonni-theme-language/twentyfifteen-fr_FR => twentyfifteen translations

You can search packages for your language from https://wp-languages.github.io-frontpage.

Just remember add this into composer.json:

"extra": {
      "dropin-paths": {
        "web/app/languages/": ["vendor:koodimonni-language"],
        "web/app/languages/plugins/": ["vendor:koodimonni-plugin-language"],
        "web/app/languages/themes/": ["vendor:koodimonni-theme-language"]
      }
    }

You can find complete working composer.json example over here: composer.json for latest Wordpress using johnpbloch/wordpress and languages.koodimonni.fi. This file has also an example of how to handle wordpress dropin-files (e.g. object-cache.php, sunrise.php, ...) using composer.json · GitHub

Notices:

  • Composer isn’t case sensitive so it doesn’t care if you require koodimoni-language/fr_FR or koodimonni-language/fr_fr. The files inside packages will still use correct naming (eg. fr_FR.po).
  • composer dropin installer understands install/update operations but can’t handle composer delete operations (yet).
  • Packages are updated into gh-pages every 30-minutes.

Source and issue tracking available in Github.

Big thanks for @haroldangenent for good feedback.

I hope you find it useful!

12 Likes

This looks great, thanks! I’ll test it out soon and might integrate it into Bedrock by default.

2 Likes

I would be really honoured! If you find some bugs or errors just tell me about it in this conversation or by email so I can get them fixed.

Great work @Koodimonni! just one question: I can find koodimonni-language/it but what about e.g. koodimonni-language/de?

And furthermore which is correct: "wordpress-languages-dir": "web/wp/wp-content/languages" or "wordpress-languages-dir": "web/app/languages", I presume the first one, anyway in booth cases the language folder doesn’t exist. Thanks.

For default Bedrock this is The right way:

"wordpress-languages-dir":"web/app/languages"

I think bedrock only looks languages from there by default.

Just make sure languages dir exists before installing languages. I made it so because I sometimes mistyped the path and installed languages to totally wrong place. I will correct the output of script to make this more clear.

I will check out where /de is hiding.

1 Like

Perfect, thanks. Just checked de, still missing.

Hey @ttss! I had some problems with the script not initiating all languages correctly. Now it’s working, Thanks for pointing that out.

Here is complete list of languages:

$language_names = array(
  'af' => 'Afrikaans',
  'ar' => 'عربي',
  'am' => 'አማርኛ',
  'as' => ' অসমীয়া ',
  'az' => 'آذربایجان دیلی',
  'be' => 'Беларускі',
  'bg' => 'Български',
  'bn' => 'বাংলা',
  'bs' => 'Bosanski',
  'by' => 'Беларускі',
  'byn' => 'ብሊና',
  'ca' => 'Сatalà',
  'ckb' => 'Kurdi',
  'cs' => 'Čeština',
  'da' => 'Dansk',
  'de' => 'Deutsch',
  'dv' => 'ދިވެހި',
  'dz' => 'རྫོང་ཁ་',
  'el' => 'Ελληνικά',
  'eo' => 'Esperanto',
  'es' => 'Español',
  'et' => 'Eesti',
  'eu' => 'Euskara',
  'fa' => '"فارسی"',
  'fi' => 'Suomi',
  'fo' => 'Føroyskt',
  'fr' => 'Français',
  'fy' => 'Frysk',
  'ga' => 'Gaeilge',
  'gl' => 'Galego',
  'haw' => 'ʻŌlelo Hawaiʻi',
  'he' => 'עברית',
  'hi' => 'हिन्दी',
  'hr' => 'Hrvatski',
  'hu' => 'Magyar',
  'id' => 'Bahasa',
  'in' => 'Bahasa',
  'is' => 'Íslenska',
  'it' => 'Italiano',
  'iu' => 'ᐃᓄᒃᑎᑐᑦ',
  'ja' => "日本語",
  'ka' => "ქართული",
  'kk' => 'Қазақша',
  'kl' => 'Kalaallisut',
  'km' => 'ភាសាខ្មែរ',
  'ko' => '한국어',
  'ky' => 'Кыргызча',
  'lb' => 'Lëtzebuergesch',
  'lo' => 'ປະເທດລາວ',
  'lt' => 'Lietuvių',
  'lv' => 'Latviešu',
  'mk' => 'Македонски',
  'mn' => 'ᠮᠣᠨᠭᠭᠣᠯ',
  'mt' => 'Malti',
  'my' => 'myanma bhasa',
  'nb' => '‪Norsk Bokmål‬',
  'nl' => 'Nederlands',
  'nn' => 'Norsk',
  'pl' => 'Polski',
  'pt' => 'Português',
  'ro' => 'Română',
  'ru' => 'Русский',
  'sk' => 'Slovenčina',
  'sl' => 'Slovenščina',
  'sq' => 'gjuha shqipe',
  'sr' => 'Српски',
  'sv' => 'Svenska',
  'th' => 'ไทย/ประเทศไทย',
  'tl' => 'Tagalog',
  'tr' => 'Türkçe',
  'ug' => '中文',
  'uk' => 'Українська',
  'ur' => 'پاکستان‎',
  'vi' => 'Tiếng Việt',
  'xh' => 'isiXhosa',
  'zh' => '中文',
  'zu' => 'isiZulu',
  'all' => 'All of the above languages',
  'nordic' => 'Finnish, Swedish, Estonian, Russian, Norwegian'
);

I will add more when asked. This is just a list that plugin wp-native-dashboard uses.

1 Like

Thanks @Koodimonni works fine, languages seem to be in the right folder. Another question: Does this addon install languages only locally or also on remote server during cap deploy? Thanks.

I haven’t tested with capistrano but if the installLanguages() function is in use it shouldn’t matter where you use this. So if you can install languages locally they will be installed correctly in remote server as well. Remote server just needs to have rsync installed (I think it’s almost always preinstalled). Just remember to run composer install or composer update with capistrano.

hey @Koodimonni I implemented your way of installing languages. I now wonder how I add the language files for different plugins I’m using. For example woocommerce? Any way to do that with your method?

Hello @vdrnn!

Nice to see that this has been useful to you.

I haven’t really given any thought for that. I’m still using these Wordpress core language packages but my workflow is a mixture of wp-cli and composer. So this hasn’t been a problem for me.

I saw that woocommerce languages are located here: https://github.com/woothemes/woocommerce-language-packs

If you want to contribute you can make a repository on github/bitbucket that has:

  • woocommerce Language files separated in plugins/ folder
  • composer.json explaining what that repo is

For example see the french language pack of mine: https://bitbucket.org/koodimonni-languages/fr/src

I’m happy to include contributions with that format in languages.koodimonni.fi and then you could install all woocommerce languages with koodimonni-language/woocommerce (or the name you chose to have). You just need have a cron script that keeps the repo up to date.

I can do all of that for you if you want to hire me. Just PM me here.

@Koodimonni: This is pretty awesome. Seems like the only viable option for language packs in Composer right now. I’m thinking about using this for our version of Bedrock.

Could you tell me something about the stability of this Composer repository? Are you committed to keeping this online?

I was also wondering about semantic versioning - right now there’s only a way to download dev-master, right?

By the way, just noticed: the language slugs seems off. For example, WordPress uses nl_NL for the Dutch language, while your repository uses nl. Almost all plugins that have translations rely on this nl_NL.

Could you clarify on how to correct this?

Hey @haroldangenent and @vdrnn

TL;DR So from now on requiring: koodimonni-language/nl_NL should work and will install woocommerce translations as well.

Thanks for your feedback. I did some additions and now newest woocommerce languagepacks from woothemes github are automatically included to basic language packs when they exists.

I corrected the shortcodes and updated language list from: http://wpcentral.io/internationalization/

Now all of the shortcodes should be corrected. My server is still downloading translation files. but in couple of hours you should be able to use updated versions.

Hey @ttss and @vdrnn!

I updated the method to be easier to use, added semantic version and original translation zip-archives straight from wordpress.org. Please update to new method mentioned above, sorry if this caused some inconvenience, but I had to change the method since translate.wordpress.org api started to misbehave.

Anyone who uses Composer should use this for languages. Thanks, @Koodimonni!

3 Likes

Thanks Koodimonni. My workflow is bedrock altered with grunt-wordpress-deploy and it works like a charm.

1 Like

I wonder if the added language files should be ignored by git. What do you say? @Koodimonni

I’m ignoring them in git myself but I guess it is just my preference. The standard way seems to be to ignore all packages handled by composer

1 Like

It would be not bad to have such a function. Is there such a thing already?