Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How can you make a variable translatable by default when you declare it with hook_variable_info()? I.e make the check box next to the variable name be checked when viewing admin/config/regional/i18n/variable.
Thanks!
Comments
Comment #1
bforchhammer CreditAttribution: bforchhammer commentedVariable
variable_realm_list_language
stores the list of variables which can be translated... you could try set that variable at install-time (hook_install of custom module, or somewhere in your install profile?).Comment #2
jmlavarenne CreditAttribution: jmlavarenne commentedThanks for your reply. I will look for it. Is this a variable? I'm not finding it in the {variable} table.
Comment #3
mrfelton CreditAttribution: mrfelton commentedWouldn't it be better if this was based on a property of the variable? Sich as the 'localize' key which seems to be unused at present. That would mean that would be easy for other modules to alter the list of variables that is translatable by implementing hook_variable_info_alter().
Comment #4
jmlavarenne CreditAttribution: jmlavarenne commentedComment #6
lklimek CreditAttribution: lklimek commentedFor anyone who needs a solution with hook_variable_info_alter() - it's not good to just check 'localize' flag because in effect you will get all vars translated (realm list contains > 30 vars in my case). So I've introduced another parameter - 'localize_by_default'.
Code sample below.
Comment #7
doublejosh CreditAttribution: doublejosh commented@lklimek Thank you! Very clever.
Rather that setting the variable via code in each pass through PHP, I might recommend setting them in a hook_install() or hook_update() so they can be cached.
Comment #8
doublejosh CreditAttribution: doublejosh commentedThis really needs to be a variable property not done in an alter. Seems like a reasonable feature request.