Example #1
0
        /**
         * Injects message bundles into the gadget output.
         * @throws GadgetException If we are unable to retrieve the message bundle.
         */
        private void InjectMessageBundles(Gadget gadget, Node scriptTag)
        {
            GadgetContext context = gadget.getContext();
            MessageBundle bundle  = messageBundleFactory.getBundle(
                gadget.getSpec(), context.getLocale(), context.getIgnoreCache());

            String msgs = bundle.ToJSONString();

            Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.Prefs.setMessages_(");

            text.appendData(msgs);
            text.appendData(");");
            scriptTag.appendChild(text);
        }
Example #2
0
        /**
         * Substitutes all hangman variables into the gadget spec.
         *
         * @return A new GadgetSpec, with all fields substituted as needed.
         */
        public GadgetSpec substitute(GadgetContext context, GadgetSpec spec)
        {
            MessageBundle bundle =
                messageBundleFactory.getBundle(spec, context.getLocale(), context.getIgnoreCache());
            String dir = bundle.getLanguageDirection();

            Substitutions substituter = new Substitutions();

            substituter.addSubstitutions(Substitutions.Type.MESSAGE, bundle.getMessages());
            BidiSubstituter.addSubstitutions(substituter, dir);
            substituter.addSubstitution(Substitutions.Type.MODULE, "ID",
                                        context.getModuleId());
            UserPrefSubstituter.addSubstitutions(substituter, spec, context.getUserPrefs());

            return(spec.substitute(substituter));
        }