farmOS / field-kit

A modular, offline-first companion app to farmOS.
https://farmOS.org
GNU General Public License v3.0
60 stars 39 forks source link

Write a script for transferring JavaScript translations to Drupal/farmOS #377

Open jgaehring opened 4 years ago

jgaehring commented 4 years ago

@mstenta and I discussed this briefly, but I'd really like a way of programmatically transferring the strings in the JavaScript translation files over to the Drupal/farmOS translation base. I think I'd try to do it with a Node script, because that's what I'm most comfortable with, but I'll probably need some pointers from @mstenta on how best to get them into farmOS.

mstenta commented 4 years ago

Yea! So I think all we would need on the Drupal side is to create a PHP file that contains t() functions.

See for example: https://github.com/farmOS/farmOS/blob/8e52d36315860d497e4f63c63325dd914750381d/modules/farm/farm_area/farm_area.features.field_instance.inc#L216

So maybe your node packaging script could just create a file called my_module.translations.inc that looks like this:

<?php

/**
 * @file
 * Field module string translations for my_module.
 */

/**
 * Field module string translations.
 */
function my_module_farm_client_translations() {
  t('string 1');
  t('string 2');
  t('string 3');
}

I think that would be enough? My understanding is that localize.drupal.org scans PHP files for t() and builds it's list of translatable strings from that. So even though that function doesn't return anything, it serves as a place to put the strings for localize.drupal.org to pick up. I think...

jgaehring commented 4 years ago

Oh awesome! Yea, I think that would be totally possible! Thanks for jogging my memory and providing that example; that's what I needed. @rafaeltcc is making great progress, so it'd be great to get these into farmOS soon where localize.drupal.org could pick them up.