GithubHelp home page GithubHelp logo

dereuromark / cakephp-translate Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 3.0 422 KB

A CakePHP plugin to manage translations of your static content the easy way via web backend.

License: MIT License

PHP 100.00%
cakephp cakephp-plugin i18n translation po-files

cakephp-translate's Introduction

CakePHP Translate Plugin

CI Coverage Status Latest Stable Version Minimum PHP Version License Total Downloads Coding Standards

A CakePHP plugin for managing translations DB driven.

This branch is for use with CakePHP 5.0+. For details see version map.

WARNING: Not fully upgraded yet, help needed!

Key features

  • Import from POT, PO files or any service/API.
  • Web-based and without external dependencies.
  • Translate strings in all languages simultaneously.
  • Allow others to help translating without having to know technical details.
  • Auto-Translate and Auto-Suggest with Translate APIs (e.g. Google Translate PHP/JS, Yandex, ...) for efficiency.

Benefits over normal PO editing

  • Prevent duplicates, missing translations, collisions.
  • Auto-Features like trim(), h(), newlines to <p>/<br>, espacing of %s.
  • Validate placeholders ({0}, %s, ...).
  • Preview and code excerpts of references.
  • Auto-Add Controller names (singular + plural).
  • Manage in Groups (=Domains) and export/enable/disable them.
  • Creates clean PO files with all translations in usage to easier diff changes.

Included translation services via APIs

  • Google (free, limited)
  • Yandex (free, limited)
  • Transltr (free)

Add your translation engine here in a heartbeat.

Installation

Including the plugin is pretty much as with every other CakePHP plugin:

composer require dereuromark/cakephp-translate

Then, to load the plugin run the following command:

bin/cake plugin load Translate -b -r
# If you haven't loaded the Tools plugin already
bin/cake plugin load Tools -b -r

Routes are needed for the backed, the bootstrap sets up a few defaults.

Run this in console to create the necessary DB tables:

bin/cake migrations migrate -p Translate

Recommendations

Use dereuromark/cakephp-queue for larger projects to avoid timeout issues when importing PO files.

Usage

Web Backend

  • Navigate to /admin/translate/ in your browser.

CLI

  • Run bin/cake translate.

Tips

  • Use TinyAuth or alike to manage access to the translation backend for user groups.
  • Implement your own Translation engine if you want to have even better auto-suggest.

Configuration and documentation

cakephp-translate's People

Contributors

alexvanniel avatar cdvrooman avatar dereuromark avatar ravage84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cakephp-translate's Issues

MySQL Syntax Error when creating Translate Project

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default, status, created, modified) VALUES ('my-app', 0, 1, 1, '2017-05-19 ' at line 1

INSERT INTO translate_projects (name, type, default, status, created, modified) VALUES (:c0, :c1, :c2, :c3, :c4, :c5)

Ways to reproduce:

  1. CakePHP 3.4.x app setup with PHP 5.6, MySQL 5.7.12
  2. Setup as written in README
  3. Navigate to adm/translate as written in README
  4. Click Please create a project first: Project Index
  5. Click New Translate Project
  6. Fill out form and submit

mysql error - table reserved words

Hello Dereuromark,

I need to report a issue regarding mysql error which occurs due to usage of mysql reserved words as a column name. Simply, I'm not able to create a project, my query fails:

INSERT INTO translate_projects (
  name, type, default, status, created, 
  modified
) 
VALUES 
  (
    'test', 0, 0, 2, '2017-08-16 12:15:30', 
    '2017-08-16 12:15:30'
  )

because usage of words "type", "default", "status" as column name is not allowed and recommended by mysql. Please find list of all reserved words on mysql webpage: https://dev.mysql.com/doc/refman/5.5/en/keywords.html and https://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql

UPDATE: mysql version:
mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+-------------------------+
| Variable_name | Value |
+-------------------------+-------------------------+
| innodb_version | 5.7.19 |
| protocol_version | 10 |
| slave_type_conversions | |
| tls_version | TLSv1,TLSv1.1 |
| version | 5.7.19-0ubuntu0.16.04.1 |
| version_comment | (Ubuntu) |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+-------------------------+
8 rows in set (0,01 sec)

Cheers,
Miralem
error

Composer install for cakephp 4 fails

Readme says cakephp 4+ but v0.1.3 uses cakephp 3.8

composer require dereuromark/cakephp-translate

Is there currently not composer version for cakephp4?

composer require dereuromark/cakephp-translate

Using version ^0.1.3 for dereuromark/cakephp-translate
./composer.json has been updated
Running composer update dereuromark/cakephp-translate
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires dereuromark/cakephp-translate ^0.1.3 -> satisfiable by dereuromark/cakephp-translate[0.1.3].
    - dereuromark/cakephp-translate 0.1.3 requires cakephp/cakephp ^3.8.0 -> found cakephp/cakephp[3.8.0, ..., 3.9.6] but it conflicts with your root composer.json require (~4.2.0).

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Element file "Tools.Element\pagination.ctp" is missing.

Following installation by letter.

At the "Project Index" (/admin/translate/translate-projects)

I get only the
Element file "Tools.Element\pagination.ctp" is missing.

I'm not sure about which additional information would be useful.
PHP : 5.6.25
Cakephp: 3.4.8

Translation Process

When I navigate to the overview page, it shows me the following "process":

Please create a project first: Project Index	

How to Translate
1. Select domain you want to translate
2. Select language you want to translate into (or from)
3. Translate and submit the form

After working around #5 by manually inserting the project record into the DB , I had a translation project.

If I follow this process order, I should now select a (translation) domain, but I have none yet.
I guess these steps lack at least one step in between.

Extracting leads to MySQL Error

When I navigate to /admin/translate/translate-strings/extract, select both available POT files (cake, default) and rpess submit, it shows me a MySQL error:

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'translate_project_id' cannot be null

SQL Query:

INSERT INTO translate_domains (name, translate_project_id, created, modified) VALUES (:c0, :c1, :c2, :c3)

I had no way of choosing a project, though I have added one in the DB beforehand.

Use Locale instead of ISO2

(Theoretically) it is possible to have more than one locale per language.

For example one could have three locales for the German language (de):

  1. de_DE for German from Germany
  2. de_CH for German from Switzerland
  3. de_DE for German from Austria

The current implementation uses the ISO2 language code to process, extract and dump data.

Also, if one uses the full locale string as locale folder (de_CH) name instead of just the language ISO2 (de), he will end up with two locale folders.

Dumping nothing

When I navigate to /admin/translate/translate-strings/dump, I can press the submit button even though I have no locale file under src\Locale/ + {locale} yet.

This leads to an MySQL error:

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'translate_project_id' cannot be null

If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.

SQL Query:

INSERT INTO translate_domains (name, translate_project_id, created, modified) VALUES (:c0, :c1, :c2, :c3)

Allow jumping to IDE on dev PC

Basically the same solution as gourmet/whoops#13

Also useful:
Allow replacing all code __(...) with a different string from the backend with a single click.
Check all referenced files and preg_replace() it, switching it out in the POT files and in Translate backend at the same time.

Add preview modal

for translating

useful for placeholders and most importantly HTML content.

Custom template reduces usability

I tested this plugin with a project of ours that is currently under development.
Since it is a public facing application we have a totally custom template and do not include the CakePHP CSS files.

When I navigate to /admin/translate/ it looks like this:

custom-template

It seems the plugin does not provide its own default template nor other styling, thus the whole view is rendered in the front facing template which is not optimized for the plugin.

Depending on the custom styling of the application it could look worse.

Wouldn't it make sense to either include a default template with custom styling or provide instructions on what needs to be styled to make the life of an integrator easier?

Translate Shell shows no sub commands

When I run

myapp>bin\cake.bat translate

It shows:

Usage:
cake translate.translate [subcommand] [-h] [-q] [-v]

Subcommands:

help  Display some help.

To see help on a subcommand use `cake translate.translate [subcommand] --help`

Options:

--help, -h     Display this help.
--quiet, -q    Enable quiet output.
--verbose, -v  Enable verbose output.

What sub commands can I use?

No Record Action Buttons

When I navigate to the project index, I do not see any record action buttons:

no-action-buttons

HTML:

<td class="actions">
<a href="/my_app/admin/translate/translate-projects/view/1"><i class="icon icon-view fa fa-eye" title="" data-placement="bottom" data-toggle="tooltip" data-original-title="View"></i></a>
<a href="/my_app/admin/translate/translate-projects/edit/1"><i class="icon icon-edit fa fa-pencil" title="" data-placement="bottom" data-toggle="tooltip" data-original-title="Edit"></i></a>
<form name="post_591ee7a78d00d381740057" style="display:none;" method="post" action="/my_app/admin/translate/translate-projects/delete/1"><input name="_method" value="POST" type="hidden"></form>
<a href="#" onclick="if (confirm(&quot;Are you sure you want to delete # 1?&quot;)) { document.post_591ee7a78d00d381740057.submit(); } event.returnValue = false; return false;"><i class="icon icon-delete fa fa-trash" title="" data-placement="bottom" data-toggle="tooltip" data-original-title="Delete"></i></a>
</td>

Probably related to #6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.