Hi
Attached is an extended version of this module with these functions:
- Also includes fallback for entity translations
- It is possible to add more than 1 language fallback
- It is possible to add a country dependent fallback.
- Use case for this can be if you have a minority language, e.g. like Northern Sami, that are spoken in several countries: People that speak Northern Sami in Norway will prefer to get the language fallback in Norwegian, in Sweden they would like to get it in Swedish, etc. It is integrated with the Smart IP module (http://drupal.org/project/smart_ip) so that you can just track the visitors country from their IP address, and give them the correct fallback language. - It is possible to select "Fallback languages" in views language filter.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | language_fallback-2-x-branch-1989146-41.patch | 44.03 KB | siliconmind |
Comments
Comment #1
attiks commentedThanks, this looks promising
1/ Nice
2/ Now the fallback is cascading for strings, so this works: ga > en-ie > en-uk > en it will keep searching till it finds a translation.
3/ I like the idea of country specific fallback, it makes sense for more countries as well, but maybe better in a submodule
There are a lot of dependencies added to the info file, they have to be optional or in a submodule and we should limit them to what is absolutely needed: field_collection, multiple_selects
I had a quick look at the zip, but it contains a patch for bootstrap.inc, is this necessary?
Is it possible to upload a patch against the latest dev version? I think it's best to createe 2 submodules: one for entities and one for the country fallback, so people can still use only for string translation fallback.
Comment #2
hibersh commentedThe module here is try to make it possible for fallbacks like: ga > en > es, which is different from drupal's default logic that ends with en.
* the patch is for interface translation fallback
* to make submodules, we need to build core language_fallback module as kinda api, a hook_language_fallback_fallbacks_alter to allow submodules changes the fallbacks, and handle the settings form.
I think it's better to build language_fallback module as
* a core language_fallback api module which will accept a fallbacks array, and make the fallbacks. Also it will be great to cover entity_translations fallback
* a sub language_fallback_example module which for single language fallback feature
and we can create dedicated projects like language_fallback_country
Comment #3
attiks commented"fallbacks like: ga > en > es" for string translations it works like that, the only thing is that in the end you'll always end up with the default language, so it is "fallbacks like: ga > en > es > [default language]"
The translations of strings is completely different from entity translation, so we can not use the localeWithFallback class for it, we can on the other hand re use the "$fallbacks = language_fallback_fallback($langcode);" like you did in language_fallback_language_fallback_candidates_alter, but that we need to move that part to another module 'language_fallback_locale', so we can do something similar for ET (language_fallback_entity_translatation) and maybe in the future for content translation (language_fallback_content_translation). The all will use language_fallback_fallback to get possible translation, but we will be able to manage the dependencies.
Since the country fallback can be used for all types of fallbacks, we probably need our own hook so the language_fallback_country can change it if needed.
Does this makes sense? If so can we start by adding the language fallback for entities, and once that's in add the country specific things?
Example, using fallback ga > en > es
Visitor language is ga and visiting node/1
node/1 exists in ga + en + es ==> visitor sees the node in ga
node/1 exists in en + es ==> visitor sees the node in en
t('xyzzy') translated in ga + en + es ==> visitor sees xyzzy in ga
t('xyzzy') not translated ==> visitor sees xyzzy (whatever the language may be)
node/1 has field_xyzzy in ga + en + es ==> visitor sees the field in ga
node/1 has field_xyzzy in es ==> visitor sees the field in es
node/1 has field_xyzzy but not translated ==> visitor sees the field as is (whatever the language may be)
Visitor language is es and visiting node/1, country of user is set to Spain
node/1 exists in ga + en + es ==> visitor sees the node in ga
node/1 exists in en + es ==> visitor sees the node in es (country fallback)
t('xyzzy') translated in ga + en + es ==> visitor sees xyzzy in ga
t('xyzzy') translated in en + es ==> visitor sees xyzzy in es (country fallback)
t('xyzzy') not translated ==> visitor sees xyzzy (whatever the language may be)
node/1 has field_xyzzy in ga + en + es ==> visitor sees the field in ga
node/1 has field_xyzzy in es ==> visitor sees the field in es
node/1 has field_xyzzy but not translated ==> visitor sees the field as is (whatever the language may be)
Comment #4
Globalbility commentedCan you check updated module? Entity and country dependent language fallback as submodules.
Module can get the fallbacks by call language_fallback_fallbacks(), and can change the fallbacks by implementing hook_language_fallback_alter($fallbacks, $langcode).
Comment #5
attiks commentedCan you upload a patch against the latest dev version as well, it will make it easier for me to review?
Comment #6
Globalbility commentedHere you go!
Comment #7
Globalbility commented@ attiks
can we commit the patch? should I find someone else to help review it?
Comment #8
attiks commented#7 I've been very busy, but I had a quick look: it looks good, but - unless I'm wrong - the form on the language settings is removed? Does this mean people will have to use one of the sub modules?
Comment #9
Globalbility commentedI also noticed that now. Actually there is another point here:
Simple forms are only allow to set a fallback for a certain language, while the country dependent is a sets of fallbacks for each country. So you can have either have simple form or country form, by enable one, you need uninstall the other first,the old settings data can not be extended. Simple form store settings in variable table, while country settings is stored in fallback entities.
Maybe we should make them share the same field? How do you think we should solve it?
Comment #10
attiks commented#9 Tough problem, I think we have to choose one storage mechanism for both, uninstalling one to use the other one will complicate things and will likely confuse users.
Comment #11
siliconmind commentedGlobalbility asked me to sort this out so his changes can be committed back to the official release. He specifically requested particular features so I would like to ask for your opinion on implementation details, so I can provide code that will satisfy both of you :)
Please let me know what you think about that so I would know what to do next to make the modified module work the way Globalbility needs.
Comment #12
attiks commented#11
Thanks for stopping time, I'm abroad for the moment, but some quick responses
1/ AFAIK endless loops are detected in the code, if not it is a bug that needs be fixed, regardless of this issue
2/ Country specific fallback can be included in the main module if it makes the implementation easier, as long as it is an optinal feature.
3/ see 2, but great idea
4/ I had the same reaction, but I think we need to store everything in a database table, and if we do that, I would like it to be easily exportable, I think the ctools approach will be the easiest.
5/ I advocate for separate modules unless it complicates the implementation, if the code is still easy to understand when everything is inside one module, and if all extra's can easily be disabled, I don't mind using one module.
Thanks again!
Comment #13
siliconmind commentedThanks for your input. I'll probably change entities to database storage as there is a lot of parameters to store and retrieve. I think that in this particular case entities make it less readable and also less efficient.
Comment #14
attiks commentedHave a look at ctools exportables it gives us an easy way to import and export the configuration.
Comment #15
siliconmind commentedPlease take a look at this version of the module. I've changed storage mechanism from entities to database. The core fallback "engine" is still very simple, only the UI got a bit more complicated. At least in comparison to your original version.
The entity translation and country specific fallbacks are disabled by default. User has to visit module's configuration page to enable these features.
I think that this should be released as the 2.0 version, because we changed the way the fallback chains work and this is significant change. There is no upgrade path yet - I don't think that we would need ctools for that but I'm open for suggestions.
User defined fallbacks are not implemented yet. I would like to know your opinion on the module before I add more features.
Comment #16
attiks commentedAny change you can upload this as a patch as well, it will make it easier for me to review the changes?
Comment #17
siliconmind commentedPatch against 1.x-dev
Comment #18
siliconmind commentedI've Fixed few bugs and added country selection block for sites that do not use smart IP for country detection.
No user defined fallbacks yet.
Comment #19
siliconmind commentedThis is yet another and hopefully final version of the modified module.
Some fixes were applied and user defined fallbacks are also implemented.
Let me know what do you think of these changes.
Comment #20
Globalbility commentedAny updated on this issue?
Comment #21
attiks commentedI tried applying the patch, but it failed, can you use
git diffto create a new one?Also can you check the coding standards, the indentation is off, should be 2 spaces for each level.
PS: Sorry for the late reaction
can you remove commented out code
unneeded comment
trailing white space
the the --> the
debug code
did you test this on all supported databases?
$user_cahin --> $user_chain
is _SESSION needed? Will this affect performance for anonymous users?
Also, always use {} for if statements
Comment #22
siliconmind commentedSorry for the delay. I've created new patch using git.
Sorry for the indentation - my Eclipse is jerking around constantly :( I hope this is fixed now.
No I did not test this with other databases. If you have any suggestions for alternative solutions, then please share. Basically, this part of the code is required even for your basic version of the module, because the module leaves references to the "localeWithFallback" class inside variables table. If you disable the module, drupal no longer loads the file that contains class definition and you end up with fatal error.
Well, we assume that even anonymous users can set up their own fallback chains, so there is no other way to do it. Besides there is an optional smart_ip module in use, which also stores data inside the $_SESSION variable... and if it didn't then that would be a massive performance hit :)
So yes, in this use case session variables are required.
Comment #23
attiks commentedThanks for the feedback, I'm still struggling with the SESSION because it means that caching (varnish, nginx) will be no effective, can we make this part optional so site administrators can opt in/opt out
Regarding the smart_ip module, my servers are running on top of barracuda and there the IP to country resolution is done by nginx by using http headers: X-GeoIP-Country-Code, X-GeoIP-Country-Name so it would be nice if that can be used as well
Comment #24
siliconmind commentedI've changed the way $_SESSION is used. Now it will only be set if one of these is true:
There is also one new feature. The module offers new language filter option for views. You can select "Fallback languages" and filter will use all languages from the list of fallback candidates offered by core language_fallback_get_candidates() function.
Comment #25
siliconmind commentedSorry, wrong patch uploaded. This one is OK.
Comment #26
siliconmind commentedHi, can you please let us know if you are going to apply this patch?
Comment #27
attiks commented#26 Yes, I'm planning to create a 7.x-2.x version containing this patch, but there are a lot of whitespace and EOL errors, I fixed most of them but can you have a look at the code.
Comment #28
siliconmind commentedI've cleaned up leading and trailing whitespaces and also fixed few comments here and there to make them more drupalish. This is a patch against head.
Comment #29
Kojo Unsui commentedGreat feature to have language fallback in views. But it seems this is not working?
I tried #23 and #28 patches. I had to create language_fallback table manually, because language_fallback_schema() didn't create the table.
Then I had none of the patches showed up the new language filter option for views : "You can select "Fallback languages" ..." .
Could you tell me if there is a way to get this working ?
Comment #30
siliconmind commentedAs a matter of fact there isn't any new filter. The module just extends existing language filter by adding another option to chose from when setting up the language filter. Just add ordinary language filter and you should see new option like the one on the screenshot.
Comment #31
Kojo Unsui commentedThanks SiliconMind. This is exactly what I meant and understood, but despite many installing/uninstalling/patching tries ... the option Fallback Language never appeared.
AFAIK, to get your module work at this point (as it is completely re-writed), I have to apply patch #28 on dev version, and only then install the patched project... if not, the install process is not fully performed. And anyway doing so, database table is not created, as explained in #29.
So can you give me once a step by step process, or a git branch I could use, to ensure I'm doing right ?
Thanks in advance.
Comment #32
siliconmind commentedYou can get fully working module from github repo.
If current patch is not working it might be due to the fact that dev release of language fallback module changes once in a while. I don't know if maintainer is still willing to add these features, so it's kind of pointless to re-roll those patches over and over again. Use the repo from github. It's tested and works fine.
Comment #33
attiks commentedAll,
I'll try to have another look to see if we can merge it, I somehow missed #28
Comment #34
Kojo Unsui commentedThanks a lot attiks, SiliconMind, for your time and answers. I'll use github repo then, and follow this issue future posts :)
Comment #35
matsbla commented@attiks:
Any updated on this issue?
We mamaged to get a unified system for handeling fallback languages in Drupal 8:
https://www.drupal.org/node/2122175
If you add the patch so we can continue development of this module and improve it together, it will also make it easier to port these functions later to Drupal 8 module.
Hope this issue will not take another year...
Comment #36
attiks commentedI'll ask Jelle to have a look tomorrow
Comment #37
jelle_sThe patch can not be committed as-is, since there is no upgrade path (no hook_update_N() that creates the new table, migrates old settings to the new table, removes the fallback field from the languages table).
Comment #38
siliconmind commentedJelle, I can write the update code, I'ts not a problem, but the fundamental question is: are you actually willing to commit this code? It would be pointless to waste time for creating update code and get rejected after that anyway.
Comment #39
attiks commented#38 It was always the idea to merge this, I only lost track, my bad
Comment #40
siliconmind commentedOK, thanks for the info. I'll figure out something and post a patch with upgrade path within few days.
Comment #41
siliconmind commentedThis patch includes update code for 1.x branch. Should work fine but it would be great if someone currently running 1.x version could test this too.
Comment #42
attiks commentedI did a quick patch review, there are a lot of code style issues, but these can be fixed be a follow-up patch, so I propose we commit this to a new 7.x-2.x branch so people can start testing.
indentation
space after while and before {
missing dot
indentation
I assume this can be removed
no inline comments
these are arrays
should this be an option?
split in 2 lines
better to load when needed
Comment #44
jelle_sPushed to 7.x-2.x with coding style issues addressed as well.
I'll create a dev release so people can start testing.
Comment #45
matsbla commentedCool! :)