Skip to content

Commit

Permalink
translations cleanup, fix reminderss.email
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Mar 25, 2015
1 parent 9ecfa20 commit 4663630
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
104 changes: 104 additions & 0 deletions scripts/translation-stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ GROUP BY `group`, `key`
;

# this query gives a list of mismatched translations
# 3
SELECT DISTINCT lt.`group`, lt.id, ft.*
FROM ltm_translations lt
JOIN
Expand All @@ -105,6 +106,109 @@ FROM ltm_translations lt
ON (lt.locale = 'ru' AND lt.value LIKE BINARY ft.ru) AND lt.`key` = ft.key
ORDER BY `key`, `group`
;

# TODO: implement pivot and have it maintained, either with triggers or in php
# same as above but with temp tables, no benefit, however with a pivot table it is 3x faster but pivot needs to be maintained
# and updated. However if for every key, group change a single row is deleted and inserted with updates then
# the impact is spread to the changes while the benefits are accrued for every page refresh.

# 2
# DROP TABLE IF EXISTS ltm_trans_pivot;
# CREATE TABLE ltm_trans_pivot AS
TRUNCATE ltm_trans_pivot;
INSERT INTO ltm_trans_pivot
SELECT lt.`group`, lt.`key`, group_concat(CASE lt.locale WHEN 'en' THEN VALUE ELSE NULL END) en, group_concat(CASE lt.locale WHEN 'ru' THEN VALUE ELSE NULL END) ru
FROM (SELECT value, `group`, `key`, locale FROM ltm_translations
UNION ALL
SELECT NULL, `group`, `key`, locale FROM ((SELECT DISTINCT locale FROM ltm_translations) lc
CROSS JOIN (SELECT DISTINCT `group`, `key` FROM ltm_translations) lg)
) lt
GROUP BY `group`, `key`;

# DROP TEMPORARY TABLE IF EXISTS ltm_trans_pivot2;
# CREATE TEMPORARY TABLE ltm_trans_pivot2 AS
# SELECT * FROM ltm_trans_pivot;

# 3a
SELECT DISTINCT lt.`group`, lt.id, ft.*
FROM ltm_translations lt
JOIN
(SELECT DISTINCT mt.`key`, mt.ru ru, mt.en en
FROM ltm_trans_pivot mt
JOIN ltm_trans_pivot ht ON mt.`key` = ht.`key`
WHERE (mt.ru not like binary ht.ru AND mt.en like binary ht.en) or (mt.ru like binary ht.ru AND mt.en not like binary ht.en)
) ft
ON (lt.locale = 'ru' AND lt.value LIKE BINARY ft.ru) AND lt.`key` = ft.key
ORDER BY `key`, `group`
;
















# 1
SELECT NULL, `group`, `key`, locale FROM ((SELECT DISTINCT locale FROM ltm_translations) lc
CROSS JOIN (SELECT DISTINCT `group`, `key` FROM ltm_translations) lg);

DROP TEMPORARY TABLE IF EXISTS ltm_locales;
CREATE TEMPORARY TABLE ltm_locales AS
SELECT DISTINCT locale FROM ltm_translations;

DROP TEMPORARY TABLE IF EXISTS ltm_groups_keys;
CREATE TEMPORARY TABLE ltm_groups_keys AS
SELECT DISTINCT `group`, `key` FROM ltm_translations;

# 1a
SELECT NULL, `group`, `key`, locale FROM ltm_locales lc
CROSS JOIN ltm_groups_keys lg;

#2a
SELECT lt.`group`, lt.`key`, group_concat(CASE lt.locale WHEN 'en' THEN VALUE ELSE NULL END) en, group_concat(CASE lt.locale WHEN 'ru' THEN VALUE ELSE NULL END) ru
FROM (SELECT value, `group`, `key`, locale FROM ltm_translations
UNION ALL
SELECT NULL, `group`, `key`, locale FROM ltm_locales lc
CROSS JOIN ltm_groups_keys lg
) lt
GROUP BY `group`, `key`;





























SELECT DISTINCT mt.`key`, BINARY mt.ru ru, BINARY mt.en en
FROM (SELECT lt.`group`, lt.`key`, group_concat(CASE lt.locale WHEN 'en' THEN VALUE ELSE NULL END) en, group_concat(CASE lt.locale WHEN 'ru' THEN VALUE ELSE NULL END) ru
Expand Down
8 changes: 8 additions & 0 deletions scripts/translations-manager.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@ INSERT INTO ltm_translations
WHERE NOT exists(SELECT *
FROM ltm_translations tr WHERE tr.`key` = kt.`key` AND tr.`group` = kt.`group` AND tr.locale = lt.locale);

# select missing page-titles and add them
# create, delete, edit, show
INSERT INTO ltm_translations (status, locale, `group`, `key`, value, created_at, updated_at, source, saved_value)
SELECT DISTINCT 1 status, locale, 'page-titles' `group`, `key`, `value`, sysdate() created_at, sysdate() updated_at, NULL `source`, NULL saved_value
FROM ltm_translations lt
WHERE (`key` LIKE 'create-%' OR `key` LIKE 'delete-%' OR `key` LIKE 'edit-%' OR `key` LIKE 'show-%' OR `key` LIKE 'index-%') AND `group` NOT IN ('messages', 'validation', 'reminders', 'translations')
AND NOT exists(SELECT * FROM ltm_translations pt WHERE pt.`key` = lt.`key` AND pt.`group` = 'page-titles');
;

8 changes: 8 additions & 0 deletions src/Barryvdh/TranslationManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ function postFind()
return Response::json(array('status' => 'ok', 'counter' => (int)$numFound));
}

public
function postDeleteAll()
{
$numFound = $this->manager->truncateTranslations();

return Response::json(array('status' => 'ok', 'counter' => (int)$numFound));
}

public
function postPublish($group)
{
Expand Down

0 comments on commit 4663630

Please sign in to comment.