-
Notifications
You must be signed in to change notification settings - Fork 0
/
TSResourceFileType.js
185 lines (164 loc) · 5.39 KB
/
TSResourceFileType.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* TSResourceFileType.js - Represents a collection of ts files
*
* Copyright (c) 2020-2022, JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var path = require("path");
var TSResourceFile = require("./TSResourceFile.js");
/**
* @class Manage a collection of ts resource files.
*
* @param {Project} project that this type is in
*/
var TSResourceFileType = function(project) {
this.type = "ts";
this.datatype = "ts";
this.project = project;
this.extensions = [".ts"];
this.resourceFiles = {};
this.API = project.getAPI();
this.logger = this.API.getLogger("loctool.plugin.webOSTSResourceFileType");
this.extracted = this.API.newTranslationSet(project.getSourceLocale());
this.newres = this.API.newTranslationSet(project.getSourceLocale());
this.pseudo = this.API.newTranslationSet(project.getSourceLocale());
};
/**
* Return true if this file type handles the type of file in the
* given path name.
* @param {String} pathName the path to check
* @returns true if this file type handles the given path name, and
* false otherwise
*/
TSResourceFileType.prototype.handles = function(pathName) {
// ts resource files are only generated. Existing ones are never read in.
this.logger.debug("TSResourceFileType handles " + pathName + "?");
this.logger.debug("No");
return false;
};
/**
* Write out all resources for this file type. For ts resources, each
* resource file is written out by itself. This method will
* iterate through all of the resource files it knows about and cause them
* each to write out.
*/
TSResourceFileType.prototype.write = function() {
this.logger.trace("Now writing out " + Object.keys(this.resourceFiles).length + " resource files");
for (var hash in this.resourceFiles) {
var file = this.resourceFiles[hash];
file.write();
}
};
TSResourceFileType.prototype.name = function() {
return "TS Resource File";
};
/**
* Return a new file of the current file type using the given
* path name.
*
* @param {String} pathName the path of the resource file
* @return {TSResourceFile} a resource file instance for the
* given path
*/
TSResourceFileType.prototype.newFile = function(pathName, options) {
var file = new TSResourceFile({
project: this.project,
pathName: pathName,
locale: (options && options.locale) || this.project.sourceLocale,
type: this,
API: this.API
});
var locale = file.getLocale();
this.resourceFiles[locale] = file;
return file;
};
/**
* Find or create the resource file object for the given project, context,
* and locale.
*
* @param {String} locale the name of the locale in which the resource
* file will reside
* @return {TSResourceFile} the JSON resource file that serves the
* given project, context, and locale.
*/
TSResourceFileType.prototype.getResourceFile = function(locale) {
var key = locale || this.project.sourceLocale;
var resfile = this.resourceFiles && this.resourceFiles[key];
if (!resfile) {
resfile = this.resourceFiles[key] = new TSResourceFile({
project: this.project,
locale: key
});
this.logger.trace("Defining new resource file");
}
return resfile;
};
/**
* Return the translation set containing all of the extracted
* resources for all instances of this type of file. This includes
* all new strings and all existing strings. If it was extracted
* from a source file, it should be returned here.
*
* @returns {TranslationSet} the set containing all of the
* extracted resources
*/
TSResourceFileType.prototype.getExtracted = function() {
return this.extracted;
};
TSResourceFileType.prototype.getDataType = function() {
return this.datatype;
};
TSResourceFileType.prototype.getResourceTypes = function() {
return {};
};
/**
* Return the list of file name extensions that this plugin can
* process.
*
* @returns {Array.<string>} the list of file name extensions
*/
TSResourceFileType.prototype.getExtensions = function() {
return this.extensions;
};
/**
* Add the contents of the given translation set to the extracted resources
* for this file type.
*
* @param {TranslationSet} set set of resources to add to the current set
*/
TSResourceFileType.prototype.addSet = function(set) {
this.extracted.addSet(set);
};
/**
* Return the translation set containing all of the new
* resources for all instances of this type of file.
*
* @returns {TranslationSet} the set containing all of the
* new resources
*/
TSResourceFileType.prototype.getNew = function() {
return this.newres;
};
/**
* Return the translation set containing all of the pseudo
* localized resources for all instances of this type of file.
*
* @returns {TranslationSet} the set containing all of the
* pseudo localized resources
*/
TSResourceFileType.prototype.getPseudo = function() {
return this.pseudo;
};
module.exports = TSResourceFileType;