Skip to content

Instantly share code, notes, and snippets.

View felipelavinz's full-sized avatar

Felipe Lavín Z. felipelavinz

View GitHub Profile
@felipelavinz
felipelavinz / l10n.php
Created August 12, 2013 22:38
Ejemplos de funciones de localización en WordPress
<?php
/**
* Para textos que pueden estar en singular o plural: _n( $singular, $plural, $numero, $dominio_de_traduccion )
* printf() permite intercalar la variable con el número en el mensaje a traducir
*/
printf( _n( 'Hay %d usuario activo.', 'Hay %d usuarios activos.', $count, 'dominio_de_traduccion' ), $count );
/**
* Desambiguación por contexto
@felipelavinz
felipelavinz / i18n-tools.sh
Last active December 21, 2015 00:39
Herramientas de localización de WordPress
# Acceder al directorio donde vamos a obtener el repositorio
cd /var/www
# Copiar los contenidos del repositorio al directorio i18n
svn checkout http://svn.automattic.com/wordpress-i18n/tools/trunk/ i18n/
# Acceder al directorio donde están los archivos que queremos traducir
cd /var/www/proyecto/htdocs/wp-content/plugins/mi-plugin
# Crear la carpeta donde se van a almacenar las traducciones
@felipelavinz
felipelavinz / i18n_update.sh
Created August 13, 2013 14:49
Actualizar un catálogo de traducciones
# instalar las herramientas de traducción de GNU.
# en Ubuntu están en el paquete gettext, en otras distribuciones puede tener otro nombre
sudo apt-get install gettext
# acceder a la carpeta donde están los archivos del proyecto
cd /var/www/proyecto/htdocs/wp-content/plugins/mi-plugin/
# actualizar la plantilla de traducciones
php /var/www/i18n/makepot.php wp-plugin . l10n/dominio_de_traduccion.pot
<?php
$row = 1;
$per_loop = 0;
$loop = 1;
$headers = array();
$files = array();
if (($handle = fopen("datos.csv", "r")) !== FALSE){
while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
if ( $row === 1 ) $headers = $data;
@felipelavinz
felipelavinz / z-index.html
Last active December 24, 2015 18:08
z-index.html
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Z-Index</title>
<style>
body{
font-family: sans-serif;
}
figure, img{
@felipelavinz
felipelavinz / most-commented.html
Last active December 24, 2015 18:09
Ejercicio CSS
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Most Commented</title>
<link rel="stylesheet" href="https://raw.github.com/necolas/normalize.css/master/normalize.css" type="text/css">
<style type="text/css">
/* Sus estilos */
body{
background: #141414;
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
@felipelavinz
felipelavinz / post-term.php
Created October 25, 2013 05:11
post-term commands for WP-CLI
<?php
/**
* Set or explore post term associations
*
* @author Felipe Lavín Z. <[email protected]>
*/
class Post_Term extends \WP_CLI_Command{
/**
* Add a term to a post
<?php
$timezone = new DateTimeZone('America/Santiago');
$now = new DateTimeImmutable('now', $timezone );
$dds = $now->format('N');
switch ( $dds ){
// sabado
case 6:
@felipelavinz
felipelavinz / ejemplo-consulta-elastica.php
Created December 11, 2013 16:24
ejemplo de consulta utilizando Elastica
<?php
// indicar los namespace que se utilizarán
use Elastica;
use Elastica\Query;
use Elastica\Exception;
$results = null;
try {