Search

Wordpress site translation (1) install a local copy

I'm currently working on 2 WP sites. One is the sub-site of a world-wide IT organization, the other one is the main site of a local business. I had forgotten how site localization can be a pain, so here is a summary of the solutions I'm using for the 2 sites.

The main issue with any kind of site (be it WP or any other system) is access rights. If you don't have full access rights (or only limited access), you can only do what the client allows you to do. Depending of the l10n savviness of the client, that can be a lot or very little.

So let's say that you work directly for the client and you have full access rights to the site.

First you don't want to work directly on the site. You want to install the site on your machine and have it run locally to be able to see all your changes and validate them before you reproduce them online.

Also, you want to be able to manage your changes and know exactly what was that change your made for. You want to have granular control of all the modifications and for that you'll need a version control system. That way you can revert any modification any time you want.

  1. Follow the instructions here to install a "blank" WP site locally and to be able to run it: https://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP
  2. (Install and) Use the "All-in-One WP Migration" plugin on the online site to export all the data (an FTP download only won't work, there are databases, etc. that you can't access from FTP)
  3. Use that same plugin on the local site to import the site
  4. Now you have a copy of your online site running locally. Changes that you'll do locally will be live right away so that you can test them. They will not affect the online site.
  5. To have granular control of your modifications, use git to create a version control repository for your site: enter the root of your site and run "git init", add all the files to the repository.
  6. You need a robust backup system. Something that does everything automatically so that you don't loose too much data (or any data at all) in case of problem. Time Machine is good but don't hesitate to use something more sophisticated.
  7. You can now start working on the site localization.

WP is a mess when it comes to translating a whole site. There are no integrated mechanisms to access all the localizable parts: you have to use plugins to create the l10n infrastructure, then plugins to export the theme strings, then whateverelse to actually access the textual contents of the site.

I'll write more later about the second phase of the l10n: the actual translation process.

From Finder to Terminal: cd anywhere

At a point in a Mac user life, the Terminal utility and all the command line applications that it brings to the game become a daily necessity. Typically, you work in a Finder window and want to work on the window items from the command line. For that, you can go up to the parent window, select the folder that you just exited and copy it, move to terminal, hit "cd", add a space, paste the folder and hit "Enter". That's a lot of fiddling around.


I just checked and found that I needed about 10 seconds to complete the task. 10 seconds, 4 times a day, 5 times a week, 40 times a year and you've lost 8,000 seconds = more than 2 hours. Eventually you'll notice that you're wasting time on this particular task and you end up either cursing yourself that you can't go faster, or start looking for a solution.
Here is my take on the problem.
On a side note, I spent way more than 2 hours to find that solution (and all the solutions that I write about here). Namely, I had to learn enough AppleScript, then I applied that knowledge to Finder and Terminal, then I found all the issues that made this a non trivial task, then I asked around (eternal thanks to the members of the AppleScript Users list hosted by Apple), then I tried a new implementation, then I was not satisfied with it, rewrote the whole thing and that's where I stand today. But the time spent on learning AppleScript and the workings of the various applications translates into knowledge (along with its own lot of frustration) that I can apply to other issues, while not spending that time only translates in frustration and a sense that you can't do much with computers...




use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
activate
try # if what is selected in Finder is a folder, then use that folder
if class of item 1 of (selection as list) is folder then
set myFolder to item 1 of (selection as alias list)
else # if nothing is selected or if the selection is not a folder, use the parent folder
set myFolder to insertion location as alias
end if
on error # if nothing works, default to using the Desktop
set myFolder to desktop as alias
end try
set myPath to quoted form of (POSIX path of myFolder)
set myCommand to "cd " & myPath
end tell

# I use a separate "handler" to launch the command.
# That handler can be saved in a script library so as to be able to call it from other scripts

my launchMyCommand(myCommand)

# A handler is useful because what matters is what it outputs, not how it works.
# So, if at one point in the future I decide that this way of launching a command in Terminal is not efficient anymore, I can change the way the handler works but I won't have to change the scripts that call it.

on launchMyCommand(myCommand)
# First I use GUI scripting to create a new Terminal window
tell application "Terminal" to activate
tell application "System Events" to tell application process "Terminal"
set frontmost to true
delay 0.1
keystroke "n" using {command down}
end tell
# Then I ask the newly created window to run the command
tell application "Terminal"'s front window
delay 0.1
do script myCommand in its last tab
activate
end tell
# And I eventually merge that window to the other so as to keep everything tidy
tell application "System Events" to tell application process "Terminal"
set frontmost to true
delay 0.1
keystroke "m" using {control down, command down}
end tell
return

end launchMyCommand

I save this script as an AppleScript application and I call it ">cd". Now when I am working in Finder, I just call Spotlight with a system shortcut, I start hitting >c and Spotlight autocompletion proposes >cd.app, I hit Enter and I'm in Terminal with a window opened on the item I wanted.