Changeset 9ba8f53e


Ignore:
Timestamp:
Jun 15, 2016 3:03:17 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e7f82c8
Parents:
47f0bbb
Message:

Translate: Add method to set language in standalone app context
i2psnark:

  • add form to set language in standalone context
  • add Ukrainian and Japanese translations
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • .tx/config

    r47f0bbb r9ba8f53e  
    157157trans.hu = apps/i2psnark/locale/messages_hu.po
    158158trans.it = apps/i2psnark/locale/messages_it.po
     159trans.ja = apps/i2psnark/locale/messages_ja.po
    159160trans.nb = apps/i2psnark/locale/messages_nb.po
    160161trans.nl = apps/i2psnark/locale/messages_nl.po
     
    167168trans.sv_SE = apps/i2psnark/locale/messages_sv.po
    168169trans.tr_TR = apps/i2psnark/locale/messages_tr.po
     170trans.uk_UA = apps/i2psnark/locale/messages_uk.po
    169171trans.vi = apps/i2psnark/locale/messages_vi.po
    170172trans.zh_CN = apps/i2psnark/locale/messages_zh.po
  • apps/i2psnark/java/build.xml

    r47f0bbb r9ba8f53e  
    212212        <zipfileset src="../../streaming/java/build/streaming.jar" />
    213213        <zipfileset src="../../systray/java/build/systray.jar" />
     214        <!-- Countries translations. The i2psnark translations are in the war but it's easier to put these here -->
     215        <!-- 300KB just to translate "Brazil", but why not... -->
     216        <fileset dir="../../routerconsole/java/build/obj" includes="net/i2p/router/countries/*.class" />
    214217        <manifest>
    215218            <attribute name="Main-Class" value="org.klomp.snark.standalone.RunStandalone"/>
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r47f0bbb r9ba8f53e  
    4343import net.i2p.util.SimpleTimer;
    4444import net.i2p.util.SimpleTimer2;
     45import net.i2p.util.Translate;
    4546
    4647import org.klomp.snark.dht.DHT;
     
    128129    private static final String PROP_USE_DHT = "i2psnark.enableDHT";
    129130    private static final String PROP_SMART_SORT = "i2psnark.smartSort";
     131    private static final String PROP_LANG = "i2psnark.lang";
     132    private static final String PROP_COUNTRY = "i2psnark.country";
    130133
    131134    public static final int MIN_UP_BW = 10;
     
    255258        _idleChecker = new IdleChecker(this, _peerCoordinatorSet);
    256259        _idleChecker.schedule(5*60*1000);
     260        if (!_context.isRouterContext()) {
     261            String lang = _config.getProperty(PROP_LANG);
     262            if (lang != null) {
     263                String country = _config.getProperty(PROP_COUNTRY, "");
     264                Translate.setLanguage(lang, country);
     265            }
     266        }
    257267    }
    258268
     
    775785                             String startDelay, String pageSize, String seedPct, String eepHost,
    776786                             String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
    777                              String upLimit, String upBW, boolean useOpenTrackers, boolean useDHT, String theme) {
     787                             String upLimit, String upBW, boolean useOpenTrackers, boolean useDHT, String theme,
     788                             String lang) {
    778789        synchronized(_configLock) {
    779790            locked_updateConfig(dataDir, filesPublic, autoStart, smartSort,refreshDelay,
    780791                                startDelay,  pageSize,  seedPct,  eepHost,
    781792                                eepPort,  i2cpHost,  i2cpPort,  i2cpOpts,
    782                                 upLimit,  upBW, useOpenTrackers, useDHT,  theme);
     793                                upLimit,  upBW, useOpenTrackers, useDHT,  theme,
     794                                lang);
    783795        }
    784796    }
     
    787799                             String startDelay, String pageSize, String seedPct, String eepHost,
    788800                             String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
    789                              String upLimit, String upBW, boolean useOpenTrackers, boolean useDHT, String theme) {
     801                             String upLimit, String upBW, boolean useOpenTrackers, boolean useDHT, String theme,
     802                             String lang) {
    790803        boolean changed = false;
    791804        boolean interruptMonitor = false;
     
    893906
    894907        }
     908
     909        // Standalone (app context) language.
     910        // lang will generally be null since it is hidden from the form if in router context.
     911
     912        if (lang != null && !_context.isRouterContext() &&
     913            lang.length() >= 2 && lang.length() <= 6) {
     914            int under = lang.indexOf('_');
     915            String nlang, ncountry;
     916            if (under > 0 && lang.length() > under + 1) {
     917                nlang = lang.substring(0, under);
     918                ncountry = lang.substring(under + 1);
     919            } else {
     920                nlang = lang;
     921                ncountry = "";
     922            }
     923            String olang = _config.getProperty(PROP_LANG);
     924            String ocountry = _config.getProperty(PROP_COUNTRY);
     925            if (!nlang.equals(olang) || !ncountry.equals(ocountry)) {
     926                changed = true;
     927                _config.setProperty(PROP_LANG, nlang);
     928                _config.setProperty(PROP_COUNTRY, ncountry);
     929                Translate.setLanguage(nlang, ncountry);
     930            }
     931        }
     932
     933
    895934
    896935        // Start of I2CP stuff.
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    r47f0bbb r9ba8f53e  
    4545import org.klomp.snark.TrackerClient;
    4646import org.klomp.snark.dht.DHT;
     47import org.klomp.snark.standalone.ConfigUIHelper;
    4748
    4849/**
     
    955956          *****/
    956957            if (newURL != null) {
     958                newURL = newURL.trim();
    957959                String newDir = req.getParameter("nofilter_newDir");
    958960                File dir = null;
     
    11421144            //String openTrackers = req.getParameter("openTrackers");
    11431145            String theme = req.getParameter("theme");
     1146            String lang = req.getParameter("lang");
    11441147            _manager.updateConfig(dataDir, filesPublic, autoStart, smartSort, refreshDel, startupDel, pageSize,
    11451148                                  seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts,
    1146                                   upLimit, upBW, useOpenTrackers, useDHT, theme);
     1149                                  upLimit, upBW, useOpenTrackers, useDHT, theme, lang);
    11471150            // update servlet
    11481151            try {
     
    21992202                  + "title=\"");
    22002203        out.write(_t("If checked, ignore words such as 'the' when sorting"));
    2201         out.write("\" >" +
    2202 
    2203                   "<tr><td>");
     2204        out.write("\" >");
     2205
     2206        if (!_context.isRouterContext()) {
     2207            try {
     2208                out.write("<tr><td>");
     2209                out.write(_t("Language"));
     2210                out.write(": <td>");
     2211                // class only in standalone builds
     2212                out.write(ConfigUIHelper.getLangSettings(_context));
     2213            } catch (Throwable t) {}
     2214        }
     2215
     2216        out.write("<tr><td>");
    22042217        out.write(_t("Theme"));
    22052218        out.write(": <td><select name='theme'>");
     
    23592372                  "</table></div></div></form>");
    23602373    }
    2361    
     2374
    23622375    /** @since 0.9 */
    23632376    private void writeTrackerForm(PrintWriter out, HttpServletRequest req) throws IOException {
  • build.xml

    r47f0bbb r9ba8f53e  
    18351835
    18361836    <!-- standalone i2psnark zip -->
    1837     <target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray" >
     1837    <!-- console dependency for countries bundle -->
     1838    <target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray, buildRouterConsole" >
    18381839        <ant dir="apps/i2psnark/java" target="standalone" />
    18391840        <copy file="apps/i2psnark/java/i2psnark-standalone.zip" todir="." />
  • core/java/src/net/i2p/util/Translate.java

    r47f0bbb r9ba8f53e  
    2828    /** @since 0.9.10 */
    2929    public static final String PROP_COUNTRY = "routerconsole.country";
    30     /** non-null, two-letter lower case, may be "" */
     30    /** non-null, two- or three-letter lower case, may be "" */
    3131    private static final String _localeLang = Locale.getDefault().getLanguage();
    3232    /** non-null, two-letter upper case, may be "" */
    3333    private static final String _localeCountry = Locale.getDefault().getCountry();
     34    /** App context only, two- or three-letter lower case, may be null */
     35    private static String _overrideLang = null;
     36    /** App context only, two-letter upper case, may be "" or null */
     37    private static String _overrideCountry = null;
    3438    private static final Map<String, ResourceBundle> _bundles = new ConcurrentHashMap<String, ResourceBundle>(16);
    3539    private static final Set<String> _missing = new ConcurrentHashSet<String>(16);
     
    140144     */
    141145    public static String getLanguage(I2PAppContext ctx) {
     146        if (!ctx.isRouterContext()) {
     147            synchronized(Translate.class) {
     148                if (_overrideLang != null)
     149                    return _overrideLang;
     150            }
     151        }
    142152        String lang = ctx.getProperty(PROP_LANG);
    143153        if (lang == null || lang.length() <= 0)
     
    152162     */
    153163    public static String getCountry(I2PAppContext ctx) {
     164        if (!ctx.isRouterContext()) {
     165            synchronized(Translate.class) {
     166                if (_overrideCountry != null)
     167                    return _overrideCountry;
     168            }
     169        }
    154170        // property may be empty so we don't have a non-default
    155171        // language and a default country
    156172        return ctx.getProperty(PROP_COUNTRY, _localeCountry);
     173    }
     174
     175    /**
     176     *  Only for use by standalone apps in App Context.
     177     *  NOT for use in Router Context.
     178     *  Does not persist, apps must implement their own persistence.
     179     *  Overrides in all contexts.
     180     *
     181     *  @param lang Two- or three-letter lower case, or null for default
     182     *  @param country Two-letter upper case, or null for default, or "" for none
     183     *  @since 0.9.27
     184     */
     185    public synchronized static void setLanguage(String lang, String country) {
     186        _overrideLang = lang;
     187        _overrideCountry = country;
    157188    }
    158189
Note: See TracChangeset for help on using the changeset viewer.