Add support for the stringoverrides module
dmitrig01 - January 18, 2009 - 04:31
| Project: | Install Profile API |
| Version: | 6.x-1.x-dev |
| Component: | CRUD functions and includes |
| Category: | task |
| Priority: | normal |
| Assigned: | dmitrig01 |
| Status: | active |
Jump to:
Description
<?php
function install_stringoverrides_import_from_file($file) {
// Start reading the file
$handle = @fopen($file, "r");
if ($handle) {
$current_override = NULL;
$current_string = NULL;
$operation = 'msgstr';
// Loop through the whole file
while (!feof($handle)) {
// Retrieve a single line
$buffer = trim(fgets($handle));
// Skip empty or comment lines
if (empty($buffer) || $buffer[0] == '#') {
continue;
}
// Continued string
if ($buffer[0] == '"') {
// See what we're reading in
$string = trim(substr($buffer, 1, -1));
if ($operation == 'msgstr' && !empty($string)) {
$current_string .= $string;
}
else {
$current_override .= $string;
}
}
else if (substr($buffer, 0, 6) == 'msgstr') {
// Retrieve the override string
$operation = 'msgstr';
$current_string = substr($buffer, 8, -1);
}
// New string
else if (substr($buffer, 0, 5) == 'msgid') {
// Save old string
if (!empty($current_string) && !empty($current_override)) {
$overrides[$current_override] = $current_string;
$current_override = $current_string = '';
}
// Read what's next
$operation = 'msgid';
$current_override = substr($buffer, 7, -1);
}
}
// Save old string
if (!empty($current_string) && !empty($current_override)) {
$overrides[$current_override] = $current_string;
}
// Clean up and save the imported data
fclose($handle);
variable_set('locale_custom_strings_'. $form_state['values']['lang'], $overrides);
}
}
?>
#1
Stick it in a contrib/stringoverrides.inc file and commit!
#2
Should you maybe upgrade to v2.0 and then work on a file?
#3
What's the status on this? I haven't use the stringoverrides module on any sites, lately, so I'm unable to test.
Shall we commit?