1------------------------------------------------------------------------------ 2-- -- 3-- Matreshka Project -- 4-- -- 5-- Localization, Internationalization, Globalization for Ada -- 6-- -- 7-- Runtime Library Component -- 8-- -- 9------------------------------------------------------------------------------ 10-- -- 11-- Copyright © 2010, Vadim Godunko <vgodunko@gmail.com> -- 12-- All rights reserved. -- 13-- -- 14-- Redistribution and use in source and binary forms, with or without -- 15-- modification, are permitted provided that the following conditions -- 16-- are met: -- 17-- -- 18-- * Redistributions of source code must retain the above copyright -- 19-- notice, this list of conditions and the following disclaimer. -- 20-- -- 21-- * Redistributions in binary form must reproduce the above copyright -- 22-- notice, this list of conditions and the following disclaimer in the -- 23-- documentation and/or other materials provided with the distribution. -- 24-- -- 25-- * Neither the name of the Vadim Godunko, IE nor the names of its -- 26-- contributors may be used to endorse or promote products derived from -- 27-- this software without specific prior written permission. -- 28-- -- 29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- 30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- 31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- 32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- 33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- 34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- 35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- 36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- 37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- 38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- 39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- 40-- -- 41------------------------------------------------------------------------------ 42-- $Revision: 1040 $ $Date: 2010-09-05 10:15:40 +0400 (Sun, 05 Sep 2010) $ 43------------------------------------------------------------------------------ 44 45package body Matreshka.Internals.Translator.XLIFF_Readers is 46 47 XLIFF_1_2_NS : constant League.Strings.Universal_String 48 := League.Strings.To_Universal_String 49 ("urn:oasis:names:tc:xliff:document:1.2"); 50 Trolltech_NS : constant League.Strings.Universal_String 51 := League.Strings.To_Universal_String 52 ("urn:trolltech:names:ts:document:1.0"); 53 Group_Name : constant League.Strings.Universal_String 54 := League.Strings.To_Universal_String ("group"); 55 Restype_Name : constant League.Strings.Universal_String 56 := League.Strings.To_Universal_String ("restype"); 57 Resname_Name : constant League.Strings.Universal_String 58 := League.Strings.To_Universal_String ("resname"); 59 Source_Name : constant League.Strings.Universal_String 60 := League.Strings.To_Universal_String ("source"); 61 Target_Name : constant League.Strings.Universal_String 62 := League.Strings.To_Universal_String ("target"); 63 XLIFF_Name : constant League.Strings.Universal_String 64 := League.Strings.To_Universal_String ("xliff"); 65 Trolltech_Linguist_Context : constant League.Strings.Universal_String 66 := League.Strings.To_Universal_String ("x-trolltech-linguist-context"); 67 68 ---------------- 69 -- Characters -- 70 ---------------- 71 72 overriding procedure Characters 73 (Self : in out XLIFF_Reader; 74 Text : League.Strings.Universal_String; 75 Success : in out Boolean) 76 is 77 pragma Unreferenced (Success); 78 79 begin 80 if Self.In_Source then 81 Self.Source.Append (Text); 82 83 elsif Self.In_Target then 84 Self.Target.Append (Text); 85 end if; 86 end Characters; 87 88 ----------------- 89 -- End_Element -- 90 ----------------- 91 92 overriding procedure End_Element 93 (Self : in out XLIFF_Reader; 94 Namespace_URI : League.Strings.Universal_String; 95 Local_Name : League.Strings.Universal_String; 96 Qualified_Name : League.Strings.Universal_String; 97 Success : in out Boolean) 98 is 99 pragma Unreferenced (Qualified_Name); 100 pragma Unreferenced (Success); 101 102 begin 103 if Namespace_URI = XLIFF_1_2_NS 104 and Local_Name = Source_Name 105 then 106 Self.In_Source := False; 107 108 elsif Namespace_URI = XLIFF_1_2_NS 109 and Local_Name = Target_Name 110 then 111 Self.In_Target := False; 112 Self.Context.Translations.Insert (Self.Source, Self.Target); 113 end if; 114 end End_Element; 115 116 ------------------ 117 -- Error_String -- 118 ------------------ 119 120 overriding function Error_String 121 (Self : XLIFF_Reader) return League.Strings.Universal_String 122 is 123 pragma Unreferenced (Self); 124 125 begin 126 return League.Strings.Empty_Universal_String; 127 end Error_String; 128 129 ------------------- 130 -- Start_Element -- 131 ------------------- 132 133 overriding procedure Start_Element 134 (Self : in out XLIFF_Reader; 135 Namespace_URI : League.Strings.Universal_String; 136 Local_Name : League.Strings.Universal_String; 137 Qualified_Name : League.Strings.Universal_String; 138 Attributes : XML.SAX.Attributes.SAX_Attributes; 139 Success : in out Boolean) 140 is 141 pragma Unreferenced (Qualified_Name); 142 pragma Unreferenced (Success); 143 144 use Context_Maps; 145 146 begin 147 if Namespace_URI = XLIFF_1_2_NS 148 and Local_Name = Group_Name 149 then 150 if Attributes.Index (Restype_Name) /= 0 151 and Attributes.Value (Restype_Name) = Trolltech_Linguist_Context 152 then 153 declare 154 Context_Name : constant League.Strings.Universal_String 155 := Attributes.Value (Resname_Name); 156 Position : constant Context_Maps.Cursor 157 := Translations.Find (Context_Name); 158 159 begin 160 if Has_Element (Position) then 161 Self.Context := Element (Position); 162 163 else 164 Self.Context := 165 new Context_Record' 166 (Name => Context_Name, 167 Translations => Universal_String_Maps.Empty_Map); 168 Translations.Insert (Context_Name, Self.Context); 169 end if; 170 end; 171 end if; 172 173 elsif Namespace_URI = XLIFF_1_2_NS 174 and Local_Name = Source_Name 175 then 176 Self.Source.Clear; 177 Self.In_Source := True; 178 179 elsif Namespace_URI = XLIFF_1_2_NS 180 and Local_Name = Target_Name 181 then 182 Self.Target.Clear; 183 Self.In_Target := True; 184 end if; 185 end Start_Element; 186 187end Matreshka.Internals.Translator.XLIFF_Readers; 188