Kevin Kaland's Developer Blog

RSS
Oct 2

How can I implement language fallback better in Drupal 7?

A site I’m currently working on currently uses an approach for language fallback that is so hackish, it’s crossed the line twice and is actually rather interesting.

First, if it detects that it might need to do something, it takes control of the page delivery callback and invokes its own.

It figures out the corresponding alias for the “parent” node (the node the user would see if they went to the same alias in a language that had a source or translation there). From there, it can load the parent node.

And long story short, it then uses hook_page_build() to intercept page rendering and add the actual rendered node to the $page render array. It also hacks it up in other ways…rendering blocks, etc.

This is obviously not the optimal solution. We find ourselves having to implement many things twice because the system doesn’t have the same context as us about what we’re doing.

Recently, I’ve thought of a potentially better solution, which is using hook_inbound_url_alter() to do essentially the same sort of alias checking. This is the approach I took in https://drupal.org/project/i18n_404.

So basically I’d swap out the underlying node in a similar way but still show the same alias. I’m not sure if the language context would be properly preserved like that, but it seems easier to deal with than what I have now.

So my main question is: Is there a module for this? Or at least something I could base off? I have a number of regression tests in our custom module now, and we are planning a refactor. I want to make it count.

Generic replies OK — I am expecting to need some custom code regardless. We handle some edge cases that I don’t think a module would, like if you have a View at /frontpage and a node at /frontpage/some-node. If you go to the latter on an untranslated language domain, it would normally show you /frontpage. We intercept that and still show the node.

There’s also a “you are not being shown the language you went to” popup, but that part doesn’t really need refactoring.

Thanks!

To open source or not to open source?

Or: “How do I give a tour of the kingdom without giving away the keys?”

I’m currently working on a commercial Meteor app I’ll be taking into private beta soon, and an interesting question has reared its head. This question inevitably arises for any software project. Licensing.

Originally I thought, “I’ll AGPL it and sell subscriptions to the Official Hosted Version. People would probably rather pay me than self-install.”

And then in conversation with a friend, that bounced around in my head and I thought, “Wait. This isn’t a a library or a framework. It’s an app. The thing itself has value. I should sell the self-installed version as well. If I release it under AGPL and open-source the code, then I can only reasonably sell support.”

Also, this is a product aimed at more-or-less personal needs. Maybe power personal users, but in any case it’s not conceived for business users.

So now I’m thinking straight-up closed source, and a standard commercial license/one-time fee for the self-installable version.

I would still like people to be able to look at the source code, though (they might have suggestions/comments)…but without eroding my revenue streams. Because I know that if it was between paying money and figuring out how to copy and build code that was just asking for it, I’d do the latter.

So, I’m at an impasse. For most stuff, I love open-source, but it doesn’t seem to make sense here. But code existing in a vacuum is also boring.

Suggestions on what to do are welcome. Anyone else been in this situation?

Internationalization SSO released on drupal.org

I released another simple module on drupal.org the other day called Internationalization SSO. If you determine the site language from the domain used to access it, and you use different top-level domains (e.g. example.com, example.es, example.fr), this…

View Post

lefnire.js: the weirdest Node.js API consumer everIt must have all started with a joke on iRC that my friend lefnire, creator of HabitRPG, might just…View Post

lefnire.js: the weirdest Node.js API consumer ever

It must have all started with a joke on iRC that my friend lefnire, creator of HabitRPG, might just…

View Post

Fixing duplicate field collection item references in Drupal due to Content Translation bug

I just left a comment in the Field Collection issue queue and thought it’d be good to spread it more widely; maybe people need this fix.

For anyone still getting burned by this bug (or for that matter getting burned by using Node Clone on nodes with field…

View Post

Introducing Internationalization 404 for Drupal

I released a new module for Drupal a couple days ago called Internationalization 404. This module helps you automatically use Content Translation-translated localized language versions of your 404, 403, and home pages.

Normally, you have to install…

View Post

HabitRPG and Remember the Milk Synchronization on the Command-Line

If you, like me, are a user of both HabitRPG and Remember the Milk, you may have been looking for a way to link the two. I developed habitrpg-todo-sync (HabitRPG Todo Synchronization) to do just that.

The README file explains in good detail how to use it.

View Post

DrupalCamp alert: DrupalCamp Gothenburg 2013!

If you haven’t been following any of the calendars listing DrupalCamps, you may have missed the arrangement that’s coming up in Gothenburg, Sweden in a couple weeks. This wouldn’t be surprising, since it’s being marketed in Swedish. People of all…

View Post

What I want in a Drupal development VM

I’ve tried a few of the Vagrant-based tools floating around and haven’t quite found what I wanted yet. So I thought I’d write it down. Once I did, I thought it’d make sense to post the list and see if anyone had input.

Without further ado:

Has to have

AUTOMATIC SETUP of Drupal.
SETUP AUTOMATION — Rakefile or whatever.
CONFIGURABILITY - change memory, CPUs, IP, mostly memory
PERFORMANCE - don’t slow me down?
WORK ON MY MACHINE - don’t make me jump through hoops
NFS folder sharing.

Nice to have

AUTOMATIC INSTALLATION of modules (or customizable makefile), declarable prior to running VM.

Which ones have I tried?

drush-vagrant (drupal-up and aegir-up)

vagrant-ariadne

Closest so far?

drupal-up, actually. aegir-up with the maintainer profile was almost there, but it it is broken atm :( The problem with drupal-up is that it doesn’t have NFS and isn’t conceived with it, so it fails “NFS” and “work on my machine.”

Do I need all these windows open!? (or: silence, MacBook fan!)

I’m faced with a peculiar, though probably common, plight.

My Mac eats up too much memory. And I have 16 GB.

Now, Mac OS X’s memory management is not to die for. This is evidenced by how 7.61 GB is currently allocated for swap despite me probably not needing that much. But that’s another story. I have to play the game within the parameters of the game, so obviously I have too much stuff open.

I used to run 3 VirtualBox/Vagrant VMs — one with 256 MB (since merged with the next one), one with around 1280 MB, and one with 4 GB (since knocked down to 3 GB).

So, 2 VMs, one 3 GB and one a bit over 1 GB. Two Chromes (two different profiles, personal and work) and my other usual always-running apps (iTerm2, Spotify, Skype, TogglDesktop, among others) exhaust all the memory.

I’d probably be best off restarting more often. And so that’s what I want to write/think about in this post — how can I close things down and/or restart quickly but still be able to regain context on projects I was working on? The latter issue — how to regain context on projects — is actually part of a larger question, and one that I’m slowly trying to solve.

It obviously depends on the project. For me, a “project” usually consists of an iTerm2 window with a tmux session inside, possibly (but not usually) an SSH session or two, a MacVim window, a running Vagrant VM (but if working on the server, then the tmux session is within the SSH session), and a Chrome window or two. The only part here that is actually tricky to save state on is the local tmux session. I probably need to teach myself to use one of the tools for automating tmux startup (e.g., open certain windows) and start writing definitions per project.

But I kinda wish there was something that would just care about all that and do it for me. I’d pay money for that. I’m sure I could probably also do something with AppleScript, but I dunno…it’s not really worth it.

But achieving cheap project resumption is definitely a nagging goal of mine. If someone solves it well and reads this, please let me give you money. Otherwise, I’ll probably wind up cobbling together more stuff to solve it for myself (and maybe collect some money of my own).