1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.localization.internal

File DefaultContextualLocalizationManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
8
2
1
86
41
3
0.38
4
2
1.5

Classes

Class Line # Actions
DefaultContextualLocalizationManager 43 8 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 22 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.localization.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.localization.ContextualLocalizationManager;
28    import org.xwiki.localization.LocalizationContext;
29    import org.xwiki.localization.LocalizationManager;
30    import org.xwiki.localization.Translation;
31    import org.xwiki.rendering.block.Block;
32    import org.xwiki.rendering.renderer.BlockRenderer;
33    import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
34   
35    /**
36    * Default implementation of {@link ContextualLocalizationManager}.
37    *
38    * @version $Id: 0ee56347bfef5808878e6c25fba5f070d2ebf340 $
39    * @since 5.0M1
40    */
41    @Component
42    @Singleton
 
43    public class DefaultContextualLocalizationManager implements ContextualLocalizationManager
44    {
45    /**
46    * The actual localization manager.
47    */
48    @Inject
49    private LocalizationManager localizationManager;
50   
51    /**
52    * Used to get the current {@link java.util.Locale}.
53    */
54    @Inject
55    private LocalizationContext localizationContext;
56   
57    /**
58    * The plain text renderer.
59    */
60    @Inject
61    @Named("plain/1.0")
62    private BlockRenderer plainRenderer;
63   
 
64  8295 toggle @Override
65    public Translation getTranslation(String key)
66    {
67  8295 return this.localizationManager.getTranslation(key, this.localizationContext.getCurrentLocale());
68    }
69   
 
70  8295 toggle @Override
71    public String getTranslationPlain(String key, Object... parameters)
72    {
73  8295 Translation translation = getTranslation(key);
74   
75  8295 if (translation == null) {
76  3932 return null;
77    }
78   
79  4363 Block block = translation.render(parameters);
80   
81  4363 DefaultWikiPrinter wikiPrinter = new DefaultWikiPrinter();
82  4363 this.plainRenderer.render(block, wikiPrinter);
83   
84  4363 return wikiPrinter.toString();
85    }
86    }