Closed (fixed)
Project:
Timeago
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Oct 2013 at 14:01 UTC
Updated:
20 Sep 2014 at 21:10 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
heylookalive commentedPatch. Looking at it will need to review how/in what order the settings are passed due to the possibility of having translation JS files.
Comment #2
heylookalive commentedThinking on the translation issue, this is probably better off living in Drupal instead of JS files so it's more in line with the whole translation approach, with the patch changes you can change everything that the JS translation files do. Whilst a hassle for people upgrading, as long as release notes were clear (and people checked them :/) this would be acceptable in my opinion - but it's up to you guys (the maintainers).
Also forgot to add in variable_del type action on uninstall for the many new vars.
Comment #3
icecreamyou commentedI don't mind the premise of this patch (allowing people to configure the strings from within the module's settings page) but it can't break backwards compatibility. That means existing translation files should continue working after upgrading. Additionally, input in the settings fields must be translatable so that it works for multiple languages. And variables need to be deleted individually since deleting anything that starts with "timeago_" could unintentionally remove variables not set by this module.
Comment #4
heylookalive commentedOK, I've tweaked this so if there is a translation file then the module makes no attempt to use the strings definable via the UI. I've also added an error message to the UI form stating this. This will preserve backwards compatibility. Via the new method this will be translatable via locale etc in a standard way as the strings are passed through t(); prior to being passed to the JavaScript settings.
I've not restored the code in the module JS file as by the looks of it this wouldn't have worked - could be wrong. If you were to have a translation file this would be added after the module JS file, therefore overwriting anything you set by doing
jQuery.timeago.settings.strings =...(we're missing "wordSeparator" here by the way) andDrupal.t(....On the variables, whilst true it's poor practice to not namespace your variables with "modulename_" and if you have a lot of variables I don't see anything too wrong with this, and plenty of other contrib projects do this. That said I can adjust the patch if you feel strongly about this.
Comment #5
icecreamyou commentedIdeally we'd also hide the UI that allows defining custom strings in that case.
t()does not support reading variables. This requires i18n support.String translation in Drupal 7 has a one-to-one mapping, so translating a single space to a different character or set of characters could have unexpected repercussions. Under the current system, the wordSeparator defaults to a space (which makes sense in almost all cases) and can be overridden by translation files if necessary, so since using Drupal.t() didn't make sense for it there was no reason to include it. A better way to translate the wordSeparator might be a hack like
t('@wordseparator', ' '). I'm not sure whether your approach of just not translating it works for all languages.The problem is not that this project could use variables that are improperly prefixed; the problem is that other modules could have "timeago_" at the start of their names. For example, someone could write a module like "timeago_node" or "timeago_js" or something and uninstalling this module shouldn't affect those variables.
Patch review:
Better: "Override Timeago script settings"
'#title' => t('Refresh Timeago dates after'),
'#suffix' => ' '. t('milliseconds'),
'#title' => t(''Set the "title" attribute of Timeago dates to a locale-sensitive date'),
'#description' => t('If this is disabled (the default) then the "title" attribute defaults to the original date that the Timeago script is replacing.'),
'#title' => t('Do not use Timeago dates after'),
'#suffix' => ' '. t('milliseconds'),
'#description' => t('Set to zero or leave blank to always use Timeago dates.'),
The default value passed to each
variable_get()here should be passed throught().This message should (A) be an error if we can detect that translation files will in fact be used, (B) use a semicolon instead of a comma, and (C) ideally use
theme_status_messages()instead of assuming the default markup." " (a space)Numeric fields you added should be validated
I prefer explicit casts: (int) and (bool)
Why is this done before translation? Also the default values passed to
variable_gethere should be passed throught()firstOnly fields with values should be translated; t('') makes no sense
Comment #6
heylookalive commentedI'd disagree, it's worth showing what's available to configure so they can be better informed if they want to switch to this method over the JS files. The fieldset is collapsed by default.
You're right, this applies to any use of
t();in my previous patch (removed for now so we can discuss). If we want to provide the opportunity to translate these strings then we should implement hook_variable_info so it can be translatable via i18n + variable modules (see link). This would mean that we shouldn't t the default values in the form, and intimeago_add_js();we would switch between usingvariable_get();orvariable_get_value();if it's present.https://drupal.org/node/1113374
On
wordSeparatorthis isn't passed along in the module JS file, and by the looks of it any settings passed (the chunk of code that usesDrupal.t();) won't work. The module JS file is included, then directly after the custom JS language file is included (if present) overwriting anything that might come from Drupal. You're right in that we don't want tot();as it's a space which could be easy to misunderstand, this is where i18n + variable solves this issue.hook_uninstallvariable deletion - this has been altered.Patch review:
1. Changed.
2. Makes for a better experience, changed. Think you meant
#field_suffixbtw.3. Changed.
4. Changed with slight tweak, we don't want to allow for anything other than an int.
5. This is related to how things should be translated.
6. A - I wouldn't call it an error if the user has opted to use the JS translation files but this depends on how you want people to use your module, and is your call. B - Done. C -
theme_status_messages().behaves a bit different, you can't pass it the messages to output as it grabs anything set viadrupal_set_messages();. Open to suggestion on this.7. Changed.
8. Implemented, this is why we don't want to allow 4. to be blank. Done using
#element_validatein core, neat.9. Changed.
10. That diff looks a bit out, are you reviewing the latest patch? The order in which things are added/what's added is to allow for backwards compatibility.
11. Good point, altered the method in which values are iterated over and
check_plained, t will come back once we've agreed on translation stuff.Comment #7
heylookalive commentedI've returned to this as this is something I need, could someone review please? :)
Comment #8
icecreamyou commentedThis is basically what should happen.
Actually I was suggesting custom validation to allow leaving the field blank, because I dislike the pattern of using zero as a default value for non-coders.
There is a workaround but I forget what it is. Oh well.
Comment #9
heylookalive commentedOK, here we go! It's been a while (coming up on a year) since I looked at this but the patch seems about right. Made against a fresh checkout of 2.x branch.
1. Have refactored to integrate and make use of the variable module if available.
2. I can't think of a way to word this that is clearer than the help text "Set to zero to always use Timeago dates.". If you can think of a more effective way am all ears. A blank field doesn't seem like the right UX fit for this.
3. Righto, will shelve this.
If you're happy with the patch then will do a round of testing (imagine others will too) then I'd hope for a stable release once everyone's happy :)
Comment #10
icecreamyou commentedI'm pretty happy with this, just a few remaining (mostly semantic) fixes. Thanks for working on this.
Use
$, notjQuery.$gets captured in scope with the version of jQuery that exists when the file is loaded, whereas if you usejQueryit will use whatever has since taken over that variable name, which may not have the relevant timeago methods and properties attached.Instead of commenting out code, I'd prefer to just remove it
element_validate_integeris incorrect, because it will pass for negative integers. The description should be "Leave blank to always use Timeago dates," the default value should be the empty string, and the validation condition should beempty($val) || (is_numeric($val) && intval($val) == $val && $val > 0). No need to change the code that populates the JavaScript settings because it already casts to an integer."remove them to make use of"... also, we should be able to detect whether a JS file will be used instead and change the error to say that the settings definitely won't apply.
(int) intval(...)is redundantFunction descriptions should be in active tense, e.g. "Grab an array of settings used by the Timeago plugin."
"This is used to build the admin form, integrate with the variable module, and populate the JavaScript settings array."
Comment #11
heylookalive commentedAll the above changes have been made (commented out chunk of code was left til reviewed), including language file detection.
Comment #13
icecreamyou commentedCommitted to dev, thanks. I made a few tweaks and attached the interdiff.
Going to let this sit in -dev for a bit as I'd like some additional testing before making a stable release.
Thanks for working on this!
Comment #14
heylookalive commented:C No commit credit!
How long do you expect you'll have this in dev? There are a few things I'd like to check on related to my needs elsewhere in the module but it's been over a year since this project has had a stable release. What would you need to feel comfortable tagging another release?
Comment #15
icecreamyou commentedYour name is in the commit message? That's what the docs say to do. I use a graphical git client but I ran the equivalent command to what Dreditor suggests.
I would like more people to test it. Historically, the majority of bugs in this module have been found after a change has been made to how the JavaScript for the plugin is added to the page. In practice, no one is using the dev branch right now according to the usage stats, so I might just wait a few weeks and then tag a new release anyway.
I'm happy to add you as a maintainer if you'd like, as long as you give me a reasonable amount of time to review changes you make before committing, at least for awhile.