Difference between revisions of "Format specifiers-es"

From AMule Project FAQ
Jump to: navigation, search
Line 1: Line 1:
 
'''MEN AT WORK, PLEASE DONT LINK IT, I WILL LINK IT WHEN FINISHED, THANX ;)'''
 
'''MEN AT WORK, PLEASE DONT LINK IT, I WILL LINK IT WHEN FINISHED, THANX ;)'''
 +
fdo. crax
  
 
+
<center>
center>
+
 
[[Format_specifiers|Inglés]] | '''Español'''
 
[[Format_specifiers|Inglés]] | '''Español'''
 
</center>
 
</center>

Revision as of 14:22, 31 October 2006

MEN AT WORK, PLEASE DONT LINK IT, I WILL LINK IT WHEN FINISHED, THANX ;) fdo. crax

Inglés | Español


Introducción

aMule se realiza en el lenguaje de programación C++. Este lenguaje permite gestionar de una manera sencilla los caracteres pero en algunos casos es necesario recurrir a algún que otro truco.

En el caso de que estés realizando una traducción de aMule, lo mas probable es que te encuentres una series de “cosas extrañas”. Algunas veces serán simplemente tipos de letra, pero en otras ocasiones, éstas se incluyen con un propósito determinado.

Este documento es necesario y obligado para alguien que desea o esta traduciendo el aMule. En este documento se describen todos casos de grupos de caracteres que nunca deben modificarse.

Por la tanto en este documento puedes encontrar la descripción de los grupos de caracteres que no debes modificar y cual es la explicación de cada uno de ellos..

Códigos especiales

Códigos especiales ASCII no representables

Son códigos que representan caracteres en código ASCII los cuales no pueden ser escritos con el teclado.

  • \a -> Normalmente produce una alerta sonora (en algún caso visual) como un pitido
  • \b -> Regresa hacia atrás un caracter
  • \f -> En la mayoría de los sistemas realiza una limpieza de la pantalla.
  • \n -> Finaliza la línea actual y comienza una nueva, situando el cursor al inicio de la nueva línea.
  • \r -> Va al inicio de la línea actual
  • \t -> Tabulación horizontal.
  • \v -> Tabulación vertical.
  • \<octal digits> -> Mostrará octal digits en octal
  • \x<hex digits> -> Mostrará el valor hex digits en hexadecimal

Códigos especiales de desambiguación

Los siguientes no son caracteres que no se puedan escribir mediante el teclado, pero debido a las limitaciones en el lenguaje de programación C++ son necesarios para utilizarlos como:

  • \? -> muestra un signo de interrogación ( ? ) para evitar traducciones tipográficas (no todos los compiladores soportan la traducción tipográfica, por lo que no siempre es necesario)
  • \\ -> Muestra un slash ( \ )
  • \' -> Muestra una comilla simple ( ' )
  • \" -> Muestra comillas ( " )

Ejemplos

A continuación tenemos unos ejemplos de los códigos mostrados anteriormente. Se muestran en parejas incluyendo la línea de código y la salida que tendrá dicha línea de código en el sistema.. En otras palabras, la primera línea representa el código C++ y la segunda línea (o grupo de línea en el caso de que sea necesario explicarlo en más de una línea) explica como el código C++ de la línea anterior se ejecuta en el sistema:

    • Línea de código: "Jacobo221 is an angel\aOh, true, I am not."
    • Salida: Jacobo221 is an angelOh, true, I am not (Se escuchará un pitido justo después de la palabra angel y la siguiente palabra no (Oh) no se mostrará hasta que no finalice el pitido)
    • Línea de código: "I have 6\b5 fingers in my right hand"
    • Salida: I have 5 fingers in my right hand
    • Línea de código: "Where is the <RETURN> key???\nAh, here it is!"
    • Salida: Where is the <RETURN> key???
      Ah, here it is!
    • Línea de código: "I am a BIG lier\rI'm married with Marilyn Monroe"
    • Salida: I'm married with Marilyn Monroe
    • Línea de código: "\141\115\165\x6C\x65"
    • Salida: aMule (Ten en cuenta que el valor en octal de a en código ASCII es 141, el valor en octal M es 115, el valor en octal de u es 165, el valor en hexadecimal del es 6C y por último el valor hexadecimal de e es 65)
    • Línea de código: "Isn\'t it complicated to use the \" and \\ characters\?"
    • Salida: Isn't it complicated to use the " and \ characters?

Códigos de formateo

Códigos de formateo básico

Los códigos de formateo son grupos de caracteres que serán sustituidos por otros datos. El código de formato mismo especifica por que tipo de datos será sustituido:

  • %d -> Valor decimal (signed integer type). Equivalente a %i
  • %i -> Valor decimal (signed integer type). Equivalente a %d
  • %u -> Número natural (unsigned integer type).
  • %x -> Valor hexadecimal representado en minúsculas (unsigned integer type)
  • %X -> Valor hexadecimal representado en mayúsculas(unsigned integer type)
  • %o -> Valor octal (unsigned integer type)
  • %f -> Número racional (con decimales) with the normal (showing all numbers) notation (tipos float y double)
  • %e -> Número racional (number with a floating point) con valor exponencial representado a partir de e minúscula (tipos float y double types)
  • %E -> Número racional (number with a floating point) con valor exponencial representado a partir de la E mayúscula (tipos float y double types)
  • %g -> Rational number (number with a floating point) with normal or exponential notation depending on the value. If exponential, a lowercase e will be used (both float and double types)
  • %G -> Núnero racional (number with a floating point) with normal or exponential notation depending on the value. If exponential, an uppercase E will be used (both float and double types)
  • %c -> Muestra caracteres (tipo integer)
  • %s -> Un string (array, pointer of integers type)
  • %p -> Muestra la dirección de memoria (tipo pointer)
  • %n -> The variable that is assigned to this format specifier will be given the value of the number of characters displayed up to know (tipo integer)

Type extensions

En algunos casos, algunos caracteres se pueden incluir entre el % y el carácter que especifica el tipo de dato. Este carácter insertado entre ambos significa el tipo de dato por el que va ser substituido el dato original.:

  • h -> Convertirá en short integer type. Válido para d, i, o, u, x, X y n.
  • l -> Convertirá en long integer type. Válido para d, i, o, u, x, X y n.
  • L -> Convertirá en long double type. Válido para e, E, f, F, g, G

Trucos

Además, algunos de los códigos de formato permiten realizar ciertas modificaciones a la hora de cambiar el aspecto de salida. Estos códigos deben ser insertados entre el % y el caracter:

  • - -> Alinea a la izquierda
  • + -> Muestra un símbolo ( + ) cuando el número es positivo. Válido para *d, i, e, E, f, g y G.
  • 0 -> Rellena los espacios en blanco con ceros ( 0 ). Válido para *d, i, u, x, X, o, e, E, f, g y G.
  • # -> Actuará de diversos modos dependiendo del tipo de datos.
    • o': Un cero ( 0 ) will be prepended when the data is non-zero.
    • x y X: Prepends 0x or 0X to the data, depending whether the format specifier was x or X.
    • f, e, E, g y G: Muestra la coma decimal incluso cuando el número no es decimal..
    • g y G: The trailing zeros are not removed.
  • <non-zero decimal value> -> Specifies the minimum width the data must occupy (if not all is occupied, it will be padded). Can be used together with 0.
  • .<decimal value> -> It will act in different ways depending on the type of data:
    • f, e and E: Specify the amount of decimals it is allowed to display (if .0, no decimals will be displayed).
    • s: Maximum amount of characters to display (if .0, no characters will be displayed).
  • %% -> This is not a format specifier, instead, it is only meant to be used to avoid ambiguousity. It will display a single % character.

Nota importante

NUNCA debes cambiar el orden de los códigos de formateo, causaría efectos inesperados. Deben ir en el mismo orden que en original mientras realices la traducción. Ejemplo: En el caso de que tradujeras la frase "I am %d years old and my name is %s." a "Mi nombre es  %s y tengo %d años." (ten en cuenta %s and %d han cambiado de orden), esto causaría un error fatal del aMule cuando intentara mostrar la frase..

Ejemplo

A continuación se muestran una serie de ejemplos de los codigos de formateo que vimos anteriormente. Se muestran en parejas incluyendo la línea de código y la salida que tendrá dicha línea de código en el sistema.. En otras palabras, la primera línea representa el código C++ y la segunda línea (o grupo de línea en el caso de que sea necesario explicarlo en más de una línea) explica como el código C++ de la línea anterior se ejecuta en el sistema, Los datos por los que los códigos de formateo son substituidos son aleatorios. (bueno, no exactamente aleatorios, he incluido datos con significado en cada ejemplo):


    • Línea de código: "I am %s and I am %d years old."
    • Salida: I am Jacobo221 and I am 19 years old.
    • Línea de código: "The first letter in the english alphabet is %c"
    • Salida: The first letter in the english alphabet is A
    • Línea de código: "There exists a format specifier which is %%%c"
    • Salida: There exists a format specifier which is %E
    • Línea de código: "There exists a format specifier which is %%c"
    • Salida: There exists a format specifier which is %c
    • Línea de código: "%E and %e are the same number"
    • Salida: 9.186329E+00 and 9.186329e+00 are the same number
    • Línea de código: "%g is in normal notation while %g is in exponential notation"
    • Salida: 0.25 is in normal notation while 3.234234E+34 is in exponential notation
    • Línea de código: "%+d is a positive number"
    • Salida: +5 is a positive number
    • Línea de código: "%05f says: Am I not 0-plenty?"
    • Salida: 000.250000 says: Am I not 0-plenty?
    • Línea de código: "Both %#o and %#X start with notation specifier"
    • Salida: Both 0345 and 0X65FC start with notation specifier
    • Línea de código: "%010x must be plenty of zeros"
    • Salida: 00000065fc must be plenty of zeros
    • Línea de código: "Pi number is %.2f"
    • Salida: Pi number is 3.14
    • Línea de código: "Look what happens when you read the four letters in Firefox: %.4s"
    • Salida: Look what happens when you read the four letters in Firefox: Fire

Otras herramientas

También hay otra serie de cosas que debes tener en cuenta cuando realices una traducción, así que lo mejor es que continúes leyendo este documento.

Character cases

The C++ programming language doesn't consider uppercase and lowercase letters as the same lettes. So, 'a' is a different letter from 'A' for C++ programs. In most cases, this will be insignificant for you, but when dealing with escape codes and format specifiers it does, so please remain them the same.

Leading and ending blank spaces

You will sometimes find strings with either begin or end with a space. This is not a typo. That space is there for a reason. Most usually this reason is one of the following:

  1. Appearance. Maybe it separates the string from somewhere that, without this separation, would look ugly.
  2. Future additions. In 99% of the cases, it will be because some data is going to be appended to it. Imagine you find a string like I am . Although no %s format specifier is found there, some data is going to be added later anyway. So, if the blank space wasn't kept, once translated, in the app it would look like I amme instead of I am me.

Examples

The following are examples of the above cases explained. They are unified into groups of four lines. The first line shows an original string, the second one how it should be translated (the examples are translated into spanish),the third one a possible output and the fourth line translates the translated possible output back into english so that you can understand it in case you don't speak spanish:

    • Code line: "aMule version "
    • Translation: "aMule versión "
    • Output: aMule versión 2.0.0
    • Output (in english): aMule version 2.0.0
    • Code line: " can become a %s aMule user"
    • Translation: " puede llegar a ser un %s usuario de aMule"
    • Output: Cualquiera puede llegar a ser un feliz usuario de aMule
    • Output (in english): Anyone can become a happy aMule user
    • Code line: " this line looks complete and the leading and ending spaces can be deleted because they seem typos "
    • Translation: " esta frase parece completa y los espacios del principio y del final se pueden eliminar porque deben ser un error "
    • Output: Aunque esta frase parece completa y los espacios del principio y del final se pueden eliminar porque deben ser un error no lo es porque, como se puede ver, quedaban cosas por añadir, lo cual demuestra que nunca se deben eliminar esos espacios
    • Output (in english): Allthough this line looks complete and the leading and ending spaces can be deleted because they seem typos it is not because, as you can see, there were still words to be added, so this shows you why you should never delete those spaces

Overall example

Example:

Untranslated:
msgid="I am %s and I a %d-year old\nand I\'m a happy \"aMule\" user "
msgstr=""
Would become (translation to spanish):
msgid="I am %s, %d years old\nand &I\'m a happy \"rabitty-aMule\" user "
msgstr="Soy %s y tengo %d años\ny soy un fel&iz usuario del \"conejillo-aMule\" "
Explanation:
  1. %s and %d must be copied literally since they will be substituted in the program with some string or number. General rule: anything between a character % and the next letter-character (that is, a, b, 'c, etc...) or percentage character (%) must be copied literally.
  2. \n must be copied literally too since it brakes the line into a new line. The general rule is: \ and it's very next character (can be \, a, n, t, ,f, ", ', etc) must be copied literally.
  3. & must be placed 'before the very same letter in the translation since it indicates the combination ALT+letter that will select that option.
  4. The ending space is left since in the original message it was there. Never remove startng or ending spaces, even if they look ugly. They are there for some reason. Nomally this will be because either before or after that string comes another string. For example: "Opening file " has a blank space at the end, so you can expect that right after it the name of a file will be displayed. Something like Opening file server.met