2

I'm trying to generate the pot files from my site with cake's i18n shell useing cake 2.3. As mentioned in the cake docs the shell should automatically extract the validation msgs. However, none of the validation strings turn up in my pot files.

My validation array simply looks like (also note the validationDomain):

public $validationDomain  = 'validation_errors';

public $validate = array(             
    'currency' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'Select a currency'
        ),
    ),
    'title' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'Fill out a title'
        ),
    )

... etc
)

What am i not seeing here?!

Thanks allot!

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
john23klipp
  • 506
  • 4
  • 7

5 Answers5

1

use this in app not in /app/Console

cake.bat i18n extract
Ryodo
  • 445
  • 5
  • 17
1

The full explanation is, that the _isExtractingApp() function of the extract task checks for identity between the app path in the --paths command line option and the APP constant in your app. If you are off by a trailing slash the validation error message extraction will be silently disabled.

This commit introduced the problem when adding plugin handling to the extract task.

As a workaround check your --paths option against the APP constant.

desolat
  • 4,123
  • 6
  • 36
  • 47
  • This is still broken as of `2.10.13`. It'd be cool if you could elaborate on the workaround. I can't figure out what to feed `--paths` with: `.` doesn't work and a full path like `C:\Projects\Foo` appears to totally break the command. – Álvaro González Oct 29 '18 at 09:12
0

For generating validation messages in pot files, you can use the command like this

./Console/cake i18n extract --validation-domain validation_errors

you can also refer the documentation here.

Anil kumar
  • 4,107
  • 1
  • 21
  • 36
  • Thanks for your reply! I've seen that line in the docs however that does not seem to make any difference. Due to server environment settings i am forced to use the i18n shell trough the cake i18n command (instead of ./Console/cake etc.) Would that make a difference? – john23klipp Sep 17 '13 at 10:12
  • I'm not familiar with the server environment settings etc.., But I've tried the above command for only translation of validation messages, by using `./Console/cake i18n extract` this, `I18n` didn't give me any strings into my `validation_messages.pot` file. – Anil kumar Sep 17 '13 at 10:40
  • Thing is im really going with the i18n shell. This offers only 4 options: [E]xtract, [I]nitialize [H]elp and [Q]uit. So this means i cant add extra params to the extract command. That would be strange though (not being able to extract validations msgs through the actuall shell...) – john23klipp Sep 17 '13 at 12:53
  • According to docs this should only change the name of the resulting files from `default.*` to `validation_errors.*`. In practice this doesn't seem to enable or disable validation extraction. – Álvaro González Oct 29 '18 at 09:14
0

Figured it out. Apparently the i18n shell does not work when targeting a particular folder. My validation messages were only extracted when running the shell on the whole app folder.

Hope this helps.

john23klipp
  • 506
  • 4
  • 7
0

As desolat's answer points out there's a bug in ExtractTask::_isExtractingApp() that's still present in latest version of the 2.x branch (CakePHP/2.10.13). The method compares paths without prior normalisation thus is fragile and breaks in some scenarios.

In my case it was failing because of relative paths:

Console\cake i18n extract --quiet --paths .

For whatever the reason, it only works for me when I use an absolute path with a duplicate trailing slash:

Console\cake i18n extract --quiet --paths "C:\Projects\Project Name\src\\"

A hard-coded path wasn't an option because my script is meant to be shared so I used a shell variable. My shell is CMD because I run the script through Composer on Windows:

Console\cake i18n extract --quiet --paths "%CD%\\"
Álvaro González
  • 142,137
  • 41
  • 261
  • 360