Package translate :: Package storage :: Module properties
[hide private]
[frames] | no frames]

Module properties

source code

Classes that hold units of .properties, and similar, files that are used in
   translating Java, Mozilla, MacOS and other software.

   The L{propfile} class is a monolingual class with L{propunit} providing unit
   level access.

   The .properties store has become a general key value pair class with
   L{Dialect} providing the ability to change the behaviour of the parsing
   and handling of the various dialects.

   Currently we support::
     * Java .properties
     * Mozilla .properties
     * Adobe Flex files
     * MacOS X .strings files
     * Skype .lang files


   Dialects
   ========
   The following provides references and descriptions of the various dialects supported::

   Java
   ----
   Java .properties are supported completely except for the ability to drop
   pairs that are not translated.

   The following U{.properties file
   description<http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)>}
   and U{example <http://www.exampledepot.com/egs/java.util/Props.html>} give
   some good references to the .properties specification.

   Properties file may also hold Java
   U{MessageFormat<http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html>}
   messages.  No special handling is provided in this storage class for
   MessageFormat, but this may be implemented in future.

   All delimiter types, comments, line continuations and spaces handling in
   delimeters are supported.

   Mozilla
   -------
   Mozilla files use '=' as a delimiter, are UTF-8 encoded and thus don't need \u
   escaping.  Any \U values will be converted to correct Unicode characters.
`
   Strings
   -------
   Mac OS X strings files are implemented using
   U{these<http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/StringsFiles.html>}
   U{two<http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html>}
   articles as references.

   Flex
   ----
   Adobe Flex files seem to be normal .properties files but in UTF-8 just like
   Mozilla files. This
   U{page<http://livedocs.adobe.com/flex/3/html/help.html?content=l10n_3.html>}
   provides the information used to implement the dialect.

   Skype
   -----
   Skype .lang files seem to be UTF-16 encoded .properties files.

   Implementation
   ==============

   A simple summary of what is permissible follows.

   Comments supported::
     # a comment
     ! a comment
     // a comment (only at the beginning of a line)
     /* a comment (not across multiple lines) */

   Name and Value pairs::
     # Delimiters
     key = value
     key : value
     key value

     # Space in key and around value
     \ key\ = \ value

     # Note that the b and c are escaped for epydoc rendering
     b = a string with escape sequences \t \n \r \\ \" \' \ (space) \u0123
     c = a string with a continuation line \
         continuation line

     # Special cases
     # key with no value
     key
     # value no key (extractable in prop2po but not mergeable in po2prop)
     =value

     # .strings specific
     "key" = "value";
'"

Classes [hide private]
  Dialect
Settings for the various behaviours in key=value files.
  DialectJava
  DialectJavaUtf8
  DialectFlex
  DialectMozilla
  DialectSkype
  DialectStrings
  propunit
an element of a properties file i.e.
  propfile
this class represents a .properties file, made up of propunits
  javafile
  javautf8file
  stringsfile
Functions [hide private]
Tuple (delimiter char, Offset Integer)
_find_delimiter(line, delimiters)
Find the type and position of the delimiter in a property line.
source code
 
find_delimeter(line)
Spelling error that is kept around for in case someone relies on it.
source code
Boolean
is_line_continuation(line)
Determine whether line has a line continuation marker.
source code
str
_key_strip(key)
Cleanup whitespace found around a key
source code
 
register_dialect(dialect) source code
 
get_dialect(dialect=default_dialect) source code
Variables [hide private]
  eol = "\n"
  dialects = {}
  default_dialect = "java"

Imports: re, warnings, logging, data, quote, accepts, returns, IsOneOf, base


Function Details [hide private]

_find_delimiter(line, delimiters)

source code 

Find the type and position of the delimiter in a property line.

Property files can be delimeted by "=", ":" or whitespace (space for now). We find the position of each delimiter, then find the one that appears first.

Parameters:
  • line (str) - A properties line
  • delimiters (list) - valid delimiters
Returns: Tuple (delimiter char, Offset Integer)
delimiter character and offset within line
Decorators:
  • @accepts(unicode, [unicode])
  • @returns(IsOneOf(type(None), unicode), int)

find_delimeter(line)

source code 

Spelling error that is kept around for in case someone relies on it.

Deprecated.

is_line_continuation(line)

source code 

Determine whether line has a line continuation marker.

.properties files can be terminated with a backslash (\) indicating that the 'value' continues on the next line. Continuation is only valid if there are an odd number of backslashses (an even number would result in a set of N/2 slashes not an escape)

Parameters:
  • line (str) - A properties line
Returns: Boolean
Does line end with a line continuation
Decorators:
  • @accepts(unicode)
  • @returns(bool)

_key_strip(key)

source code 

Cleanup whitespace found around a key

Parameters:
  • key (str) - A properties key
Returns: str
Key without any uneeded whitespace
Decorators:
  • @accepts(unicode)
  • @returns(unicode)