All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class TranslateReaderextends FilterReader
Filters a reader, replacing the gettext-style tags described below as they are read.

Strings are tagged with _("translateme") or _("translate {0} me", "foo")

Max two parameters. String and parameters must be double-quoted (no ngettext, no tagged parameters). Escape quotes inside quote with \". Commas and spaces between args are optional. Entire tag (from '_' to ')') must be on one line. Multiple tags allowed on one line.

Also will extract strings to a dummy java file for postprocessing by xgettext - see main(String[]).

  • Field Details

  • Constructor Details

    • TranslateReader

      public TranslateReader(I2PAppContext ctx, String bundle, InputStream in) throws IOException
      May be null for tagging only.
      Parameters:
      ctx - the context the bundle is looked up through
      bundle - may be null for tagging only
      in - UTF-8
      Throws:
      IOException - declared but never thrown; the stream is only wrapped here
    • TranslateReader

      public TranslateReader(I2PAppContext ctx, String bundle, Reader in)
      May be null for tagging only.
      Parameters:
      ctx - the context the bundle is looked up through
      bundle - may be null for tagging only
      in - the reader the tag text is pulled from
  • Method Details

    • read

      public int read() throws IOException
      Overrides:
      read in class FilterReader
      Throws:
      IOException
    • parse

      private int parse() throws IOException
      Reads the file and passes the strings to the hook.
      Returns:
      the number of tags processed
      Throws:
      IOException - if the file cannot be read
    • read

      public int read(char[] cbuf, int off, int len) throws IOException
      Overrides:
      read in class FilterReader
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class FilterReader
      Throws:
      IOException
    • ready

      public boolean ready() throws IOException
      Overrides:
      ready in class FilterReader
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterReader
      Throws:
      IOException
    • mark

      public void mark(int readLimit)
      Overrides:
      mark in class FilterReader
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class FilterReader
      Throws:
      IOException
    • markSupported

      public boolean markSupported()
      Overrides:
      markSupported in class FilterReader
    • pushit

      private void pushit(char c)
      Put in the pending parse buf.
      Parameters:
      c - the character to append to the pending input buffer
    • flushit

      private int flushit()
      Flush _inBuf to _outBuf, reset state, and return next char or -1.
      Returns:
      the next character from the output buffer, or -1 when it is empty
    • popit

      private int popit()
      Return next char from _outBuf or -1.
      Returns:
      the next character from the output buffer, or -1 when it is empty
    • translate

      private void translate()
      Clear _inBuf, translate _args to _outBuf, reset state.
    • main

      public static void main(String[] args)
      Do not comment out, used to extract tags as a part of the build process.
      Parameters:
      args - the subcommand (test or tag) followed by its file arguments
    • test

      private static void test(String file) throws IOException
      Runs the reader over one file from the command line.
      Parameters:
      file - the file to read
      Throws:
      IOException - if the file cannot be read
    • tag

      private static void tag(String[] files) throws IOException
      Tag PO files with translation metadata.
      Parameters:
      files - command line arguments; files[0] is ignored, the rest name the input files and the output file
      Throws:
      IOException - if a directory listing fails or a file cannot be read or written