ALTER TABLE lang_constants DROP INDEX cons_name , ADD UNIQUE INDEX cons_name (constant_name ASC);
This is an issue with regards to the database representation of information, and primarily concerns when people add custom/additional translation.
Adding a uniqueness constraint to the database would provide an additional check to make sure that duplicate constant’s don’t accidentally get defined when definitions are added using the interface in “Administration > Other > Language”.
If duplicates entries exist, then the results of the query in translations.inc.php
$sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
"lang_definitions.cons_id = lang_constants.cons_id WHERE " .
“lang_id=? AND constant_name = ? LIMIT 1”;
Could be unpredictable.
However with regards to the spreadsheet, when just the spreadsheet is loaded, all of the constants “should” be unique. However, if for some reason the same constant had two rows in the spreadsheet (error with the perl script somewhere, manual edits that were done incorrectly…) This extra constraint would lead to an error being generated when the spreadsheet was loaded, rather than the spreadsheet being loaded and translations potentially being unpredictable.
I’m guessing that the perl scripts work to maintain uniqueness. Changing the index to unique would provide additional “protection” when manual edits are made
What I understand is that there might be included duplicates in the spreadsheet. As far as I made translations, the only duplicates in a rows are the ones with a " " space at the end of a Constant and so also in Definitions. But translations wise for the used scripts or I can’t be of any help. For manual added translations, as long as a sentence/constant is translated there is no need for uniqueness. The translated words represent the Constant and the constant is used for interactions and not the translations. Correct me if I am wrong.
If by manual you mean to xl(…) translation characters as a part of the software this extra constant will be included or not included if needed due to not yet included in the Constant column.
You having said this, I am out! Please let’s hope other developers will jump in to support the idea of uniqueness. I did translate some different constants but were definitely in luck not to encounter problems due to uniqueness.
Pieter, thanks for your interest and desire to help.
The basic issue in my mind is that the table should have been enforcing uniqueness all along. If all that people are using is just the spreadsheet, this is a non-issue, but if someone is trying to use definitions from additional sources, there may be a problem.
I think you might be able to with a couple of messy queries using subqueries. One to update lang_definitions.cons_id to point to just one of the duplicates, and another to remove the duplicated constants. I’d have to play with it for a bit.
Then you might be left with some duplicated (lang_id, cons_id) pairs in the lang_definitions table, for which the same problem of possible duplicates exists.
Except there may also be conflict resolution needed for when multiple lang_definitions exist that might map to the same constant_name with different definitions. Which definition should win?
I am certain that appropriate queries are possible, but to make them “one-size fits all” would be difficult.
It doesn’t really matter which one wins, since the translation lookup will not have a predictable result anyway. Throwing either one away will be better than doing nothing.
Yes it’s kinda messy but I suspect do-able. Main thing is to make sure upgrading is robust.
The only manual problem that exists than is your additional translations through Administration => Others -> Translations etc…
But these new translations have to be done in the software …php …txt(?) …sql files, etc. and after the xl(…) is added give it the translation definition. This is like creating a personal local translation-file.
BTW for translation there is used: xl(…) xl t(…) xl a(…) I did not check for completeness, but there seemed to be a reason for this different translation options.
This is a “unique” situation where you may not need to spend much time worrying about upgrading the table. Could just place it in the database.sql file and then when users upgrade to the next official translation set, can fix it here:
For testing:
-Ensure a new install works.
-Will want to test to ensure funny things(ie. especially a crash) don’t happen when bringing stuff in from lang_custom if for some reason there are two items with same constant lingering in there.
Also, the perl scripts that build the translation spreadsheet are set up to not allow identical constants:
The perl script that builds the database tables from the spreadsheet does not explicitly ensure that(but is uses the spreadsheet built from above scripts and also does confirmations of constants to the official partner constant list):
A very important item I forget to mention here; the change to database.sql is actually going to do nothing(it’s good to do for clarity sake), since when it brings in the translation set on install, tables will get replaced by:
So, for testing, remember to change it there.
-brady