Code snippets for symfony 1.x

Navigation

Snippets by user Raphael Araújo

translate messages with html tags

Example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xliff PUBLIC "-//XLIFF//DTD XLIFF//EN" "http://www.oasis-open.org/committees/xliff/documents/xliff.dtd">
<xliff version="1.0">
    <file original="global" source-language="en" datatype="plaintext" date="2009-08-12T12:32:00Z">
        <header/>
        <body>
            ...
            <trans-unit>
                <source>from %from_date%&lt;br /&gt;to %to_date%</source>
                <target>de %from_date%&lt;br /&gt;até %to_date%</target>
            </trans-unit>
        </body>
    </file>
</xliff>
 

Use '&lt;' and '&gt;' to replace '<' and '>'. respectively.

by Raphael Araújo on 2012-01-26, tagged i18n  translate  xml 

String Slug

<?php
 
function slugString($string, $replacement = '_')
{
  $aux = preg_quote($replacement, '/');
 
  $map = array(
    '/à|á|ã|â/' => 'a',
    '/è|é|ê|ẽ|ë/' => 'e',
    '/ì|í|î/' => 'i',
    '/ò|ó|ô|õ|ø/' => 'o',
    '/ù|ú|ũ|û/' => 'u',
    '/ç/' => 'c',
    '/ñ/' => 'n',
    '/ä|æ/' => 'ae',
    '/ö/' => 'oe',
    '/ü/' => 'ue',
    '/Ä/' => 'Ae',
    '/Ü/' => 'Ue',
    '/Ö/' => 'Oe',
    '/ß/' => 'ss',
    '/[^\w\s]/' => ' ',
    '/\\s+/' => $replacement
  );
 
  return preg_replace(array_keys($map), array_values($map), $string);
}
 

based on http://api.cakephp.org/view_source/inflector/#line-480

by Raphael Araújo on 2009-10-16, tagged helper  slug  text