Drupal best way to change text - drupal

I'm using the module "simplenews" and during the registration process it reads "Select the newsletter(s) to which you wish to subscribe.".
I'd like to change this line and wanted to ask what the best way is to do so without hard coding it?
Thanks in advance!

I've also done this with the custom english version just so I could override a few strings. It works and is easier than hook_form_alter, but it also creates a bit of unnecessary overhead, especially if your site is otherwise not localized/multilingual.
There is nowadays a light and easy solution, that uses the same locale system, but you don't need to setup a custom english language or code anything: the "String Overrides"-module.
http://drupalmodules.com/module/string-overrides
Surprisingly, it's one of the top rated modules, out of over 5000 module.

Since it's located in a form, an easy and quick solution would be to change it with hook_form_alter.
Another solution would be to create your own custom version of the language english in Drupal and then "translate" the string into something different.
You could also skip the translation part, and use your settings.php file. You can create some custom string override in it without enableling the locale module. From the default.settings.php file:
/**
* String overrides:
*
* To override specific strings on your site with or without enabling locale
* module, add an entry to this list. This functionality allows you to change
* a small number of your site's default English language interface strings.
*
* Remove the leading hash signs to enable.
*/
# $conf['locale_custom_strings_en'] = array(
# 'forum' => 'Discussion board',
# '#count min' => '#count minutes',
# );

Or you can use String Overrides. Some more details about this module (from its project page):
Provides a quick and easy way to replace any text on the site.
Features
Easily replace anything that's passed through t()
Locale support, allowing you to override strings in any language
Ability to import/export *.po files, for easy migration from the Locale module
Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.

Related

using GetText to translate wordpress using variables instead of default language

I want to make my wordpress theme translation ready.
I was thinking to use GetText function within wordpress like: _e('sometext')
But I was thinking, what happens when I want to change default English 'sometext', I have to go to different php files (where I used _e('sometext')) find all instances and replace it with _e('sometext2') ?
Or in my PO file I just make English column, use _e('sometext') in wp php files, but in PO file specify 'sometext2'?
I would use something similar to the concept of constants, e.g:
<?php _e('TXT_ABOUT_INTO'); ?>
TXT_ABOUT_INTO will be like a placeholder, and you will need to create a translation file for English as well as for other languages.
Yes, if you decided to replace "sometext" with "some other text" you would need to go through the templates wherever _e('sometext') appeared and replace it with _e('some other text').
But... imagine you did not wrap your text in gettext calls. Then you would have to go through your templates to replace "sometext" with "some other text".
Not a lot of difference, and if you were to do a global find & replace you'd be much less likely to accidently change something if your search term was "_e('sometext')" than "sometext".
I've followed your example, but you should be including the text domain when you wrap the text, e.g. _e('sometext', 'my-theme')

How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?

I created a view which has three exposed filters. Everything works fine except the fact that I can neither translate or change the default string (-Any-) for the dropdowns. Is there a way to change this string to something more meaningful like "Please Select" and make it translatable so the German version displays "Bitte wählen"? I have two screen captures that may be helpful:
and
A further improvement would be the ability to change the text "any" to something like "please select a (field name here)" but I am losing hope for that =)
UPDATE
IMPORTANT: On further testing, I found that if you choose to display "-Any-" from "admin/build/views/tools", then THAT IS translatable.
For anyone who wants to just change the value of "- Any -" to something in particular then use a custom module to override that looks like this:
function yourmodulename_form_alter(&$form, $form_state, $form_id) {
if($form_state['view']->name == 'your_view_name_here') {
$form['your_dropdown_name']['#options']['All'] = t('- Type -'); // overrides <All> on the dropdown
}
}
The reason you might want to do this is if you have 3 (for example) dropdowns for 3 separate fields. Then having on them wouldn't be very useful for a user (especially if you are not using labels).
In the code above just remember to change "yourmodulename" to the name of your module.
your_view_name_here should be the name of your view (replace dashes with underscores - for example "property-search-bar" would become "property_search_bar")
And change "your_dropdown_name" to the field name - I found this by using dsm($form) with the devel module installed and enabled. This is usually the field name of your drop down so it might be something like "field_my_custom_value".
Hope this helps anyone who needs it!
Three options:
You could change it with localisation, if you have that enabled already. Introducing localisation only for this string is far too much overhead.
You can change it with a form_alter, if you already alter the form anyway. Introducing a module with a hook_form alter for just one string is way too much (maintainance and performance) overhead.
You coud change it with a simple string override in your settings.php
In Drupal 7 (Drupal6 differs in details only)
/**
* String overrides:
*
* To override specific strings on your site with or without enabling locale
* module, add an entry to this list. This functionality allows you to change
* a small number of your site's default English language interface strings.
*
* Remove the leading hash signs to enable.
*/
$conf['locale_custom_strings_en'][''] = array(
'<Any>' => 'Whatever!',
);
Note though, that this will change every occurrance of the full string <Any> (case sensitive) to Whatever, not just the ones in that single form.
Views exposed filter label is not translatable in D6.
Go to Administer > Site building > Views and select tab tools.
Replace 'Label for "Any" value on optional single-select exposed filters: ' by the translatable '- Any -'.
Important: visit the views with exposed filters in at least one language which isn't your default language.
Then you can translate "- Any -" through Aminister > Site building > Translate interface (case sensitive).
Or you can simply use a line of jQuery code like this:
$(document).ready(function(){
$("#views-exposed-form-url-name-display-name #edit-tid-all a").text("All");
});
The Better Exposed Filter module allows you to change the "-any-" label in a Views exposed filter.
I'd rather go with the simple solution: String Overrides.
With this you simply add a string you want to change on your site, and replace it with anything you want (Strings of course).
May be module https://www.drupal.org/project/views_advanced_labels helps?
I found it, but have not tried it yet.
if ($form['#id'] == 'views-exposed-form-project-search-block-project-search') {
foreach ($form['#info'] as $filter_info) {
$filter = $filter_info['value'];
if ($form[$filter]['#type'] == 'select') {
$form[$filter]['#options']['All'] = $filter_info['label'];
}
}
}
If you use Better Exposed Filters module, go into Exposed Form > Exposed form style: Better Exposed Filters | Settings > look for your field > Advanced Filter Options > put "- Any -|All" in the "Rewrite the text displayed" field.

How do I dynamically change ubercart's default messages from my module

There are some products for which I would like to have a special checkout complete message that would differ from the default.
I know that I could probably do this by changing the default redirect page to something else. [And I'm not sure if that would introduce another problem]
However, I would like to know if there is a standard/better way of approaching this problem.
Thanks!,
D
Consider the String Overrides module. Here is a quote about it (from the module's project page):
Provides a quick and easy way to replace any text on the site.
Features:
Easily replace anything that's passed through t()
Locale support, allowing you to override strings in any language
Ability to import/export *.po files, for easy migration from the Locale module
Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
I guess the only other possible way of doing what I am thinking of is to override the theme function that ubercart uses to display the message. And this probably seems like it would make the most sense.
In this case I would override theme_uc_cart_complete_sale
I could set a
$_SESSION['is_special_product'] == TRUE;
and then set $message to my $special_message if it's been set.
if ($_SESSION['special_product']) {
$special_message = t('This is my special message');
$message = variable_get('special_product_message', $special_message;
}
Finally, to override from my module I will need to hook into the pre-process hook:
function $modulename_prepocess_$hook(&$message) {
if ($_SESSION['special_product']) {
$special_message = t('This is my special message');
$message = variable_get('special_product_message', $special_message;
}
}
It is important to note that it is not enough to have this function in your module. The preprocess functions are only invoked when the template file that overrides the theme function is called.
More details can be found at http://drupal.org/node/223430

Changing the QTY label in Uber Cart?

How do you change the QTY (quantity) label in UberCart (in Drupal) without actually hacking the core components? I want the label to be be months, instead of qty.
You could use the String Overrides module. Here is an excerpt from its project page:
Provides a quick and easy way to replace any text on the site.
Features:
Easily replace anything that's passed through t()
Locale support, allowing you to override strings in any language
Ability to import/export *.po files, for easy migration from the Locale module
Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
I once ran into a similar issue with Ubercart in another language (German), and we "solved" it by re-translating the string. The mentioned module should do the trick in your case.
I haven't used ubercarts, but I would guess there would be an admin section to do that. Else hook_form_alter() or hook_form_FORM_ID_alter() should be able to do the trick for you.
Unfortunately, there is no setting for this in ubercart.
Doing a search for 'Qty' (case sensitive, as there are numerous 'qty' in code) in the current ubercart-6.x-2.0-rc7 release gives seven matches:
3 in theme functions, which you'd need to override in your theme
1 in a form definition, which you'd need to change via hook_form_alter as googletorp suggested
3 in table definitions, which you'd need to change via hook_tapir_table_alter and/or hook_tapir_table_header_alter (see the hooks.php file in ubercarts doc directory for these)
So you should be able to implement your changes without changing the module itself, but given the amount of work involved, I'd try schnecks suggestion first ;)

Wordpress widget creation

%wordpress I've created to tool to turn php functions into Wordpress widgets. I use the register_sidebar_widget function but it seems like wp_register_sidebar_widget would give me more options. Is that legal?
P.S. I also generate widgets in the new 2.8 format.
register_sidebar_widget is deprecated--though it can still be used, but you could use wp_register_sidebar_widget. If you do use register_sidebar_widget might want to bracket it in an if ( function_exists('register_sidebar_widget') ) in case that function gets removed in subsequent versions.
Also, there is a plugin, Otto's PHP Code Widget, that allows PHP code in a widget.
http://codex.wordpress.org/WordPress_Widgets_Api/register_sidebar_widget
http://codex.wordpress.org/WordPress_Widgets_Api/wp_register_sidebar_widget
http://wordpress.org/extend/plugins/php-code-widget
Legal? Sure. WordPress is GPL, you can do anything you like as long as you follow the requirements of the license.

Resources