crowdfree
Version:
A crowdin compatible tool for translation and localisation of websites and applications
2 lines • 18.3 kB
JavaScript
(this.webpackJsonpundefined=this.webpackJsonpundefined||[]).push([[0],{10:function(e,t,n){},12:function(e){e.exports=JSON.parse('{"manual_description":"Crowdfree is a crowdin inspired tool for translation and localisation of websites and applications","manual_search_1":"The search field is autoselected when you enter the site. It has a few settings for increasing efficiency.","manual_search_continous_1":"Continous:","manual_search_continous_2":"By enabling continous search only exact matches will be shown. Ex","manual_search_continous_3":"cip body","manual_search_continous_4":"will match","manual_search_continous_5":"project_CIP_body","manual_search_continous_6":"but not","manual_search_continous_7":"CIP_project_body","manual_search_fulltext_1":"Fulltext:","manual_search_fulltext_2":"Fulltext allows you to search not only the key, but the content of translations. This is handy for finding a section on a site without being confident with finding it in the code.","manual_search_title":"Search","manual_setup_1":"It operates on .json locale files stored in your project. You are now looking at the Crowdfree web application - you probably got here typing something like","manual_setup_10":"would be highlighted since it is missing a norwegian translation. By clicking on","manual_setup_11":"the editor for the string would open. You will get presented with 2 input boxes - one with the english text and one empty for the norwegian translaiton. Depending on the extra services you have enabled you may also see translation suggestions from ex google translate.","manual_setup_2":"or","manual_setup_3":". By doing so we crawled your project directory for the following directory structure:","manual_setup_4":"Each file is expected to look like","manual_setup_5":"By keeping the key the same in files in different folders you can do translations. So in your","manual_setup_6":"you would have","manual_setup_7":"Upon running crowdfree you would see","manual_setup_8":"and","manual_setup_9":"in the sidebar.","manual_setup_title":"Project setup","manual_sidebar_1":"The sidebar is the most important navigation instrument on the site. It shows a list of all localisation strings in the project. Strings that are missing translations will be highlighted for extra visibility.","manual_sidebar_title":"Sidebar","manual_title":"User manual","manual_web_1":"The web interface is optimized for being able to quickly locate missing localisations and to easily translate them by providing all the needed information in one place (text in original language, other translations, suggestion from google translate etc)","manual_web_2":"This allows the user to translate effectively and be confident when gauging the translation progress.","manual_web_3":"All changes are written to file as soon as the input box is deselected - if running react in a dev environment this means the site will get updated immediately so you can gauge how well the text fits in context and whether the length is appropriate.","manual_web_title":"Web interface","program_locale_prefix":"Locale:","program_suggestions_header":"Suggestions:","program_title":"Crowdfree","search_option_continous":"Continous","search_option_fulltext":"Fulltext"}')},13:function(e,t){e.exports=function(e){return e.sort((function(e,t){return 2*Number(e.key>t.key)-1}))}},18:function(e,t,n){},21:function(e,t,n){"use strict";n.r(t);var a=n(2),s=n.n(a),r=n(11),i=n.n(r),o=(n(18),n(3)),c=n(4),l=n(6),u=n(5),h=(n(10),{en:n(12)}),d="en";function p(e){if(!1===h[localStorage.locale||d][e]||void 0===h[localStorage.locale||d][e]||""===h[localStorage.locale||d][e]){for(var t in h){var n=h[t];if(void 0!==n[e])return n[e]}return localStorage.developer?"<"+e+">":""}return h[localStorage.locale||d][e]}var j=n(1),f=n.n(j),_=n(7),b=Object({NODE_ENV:"production",PUBLIC_URL:"",WDS_SOCKET_HOST:void 0,WDS_SOCKET_PATH:void 0,WDS_SOCKET_PORT:void 0,FAST_REFRESH:!0}).REACT_APP_API_URI?"".concat(Object({NODE_ENV:"production",PUBLIC_URL:"",WDS_SOCKET_HOST:void 0,WDS_SOCKET_PATH:void 0,WDS_SOCKET_PORT:void 0,FAST_REFRESH:!0}).REACT_APP_API_URI,"/api/"):"/api/",m=[],v=0;function x(){return(x=Object(_.a)(f.a.mark((function e(t){var n;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t&&(m.push(t),v||(v=Date.now(),setInterval(Object(_.a)(f.a.mark((function e(){var t,n;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(b+"translations/since/"+v);case 2:return t=e.sent,e.next=5,t.json();case 5:n=e.sent,m.forEach(function(){var e=Object(_.a)(f.a.mark((function e(t){var a,s;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:(null===(a=n.data)||void 0===a?void 0:a.length)&&console.log(n.data),(null===(s=n.data)||void 0===s?void 0:s.length)&&(null===t||void 0===t||t(n.data));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),v=Date.now();case 8:case"end":return e.stop()}}),e)}))),500))),e.next=3,fetch(b+"translations");case 3:return n=e.sent,e.next=6,n.json();case 6:return e.abrupt("return",e.sent.data);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(){return(g=Object(_.a)(f.a.mark((function e(){var t;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(b+"locales");case 2:return t=e.sent,e.next=5,t.json();case 5:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function O(){return(O=Object(_.a)(f.a.mark((function e(){var t,n,a,s=arguments;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{file:"locale.json",key:"headertext",locale:"en",props:{value:"New english text"}},e.next=3,fetch(b+"translations/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:[t]})});case 3:return n=e.sent,e.next=6,n.json();case 6:return a=e.sent.data,m.forEach((function(e){return e(a)})),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function y(){return(y=Object(_.a)(f.a.mark((function e(t,n){var a;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("".concat(b,"translation/").concat(t,"/").concat(n));case 2:return a=e.sent,e.next=5,a.json();case 5:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var w={getTranslations:function(e){return x.apply(this,arguments)},getLocales:function(){return g.apply(this,arguments)},updateTranslation:function(){return O.apply(this,arguments)},getTranslation:function(e,t){return y.apply(this,arguments)}},k=n(13),T=n.n(k),S=n(9),C=n(0),N=function(e){Object(l.a)(n,e);var t=Object(u.a)(n);function n(){var e;return Object(o.a)(this,n),(e=t.call(this)).state={search:"",searchFulltext:"true"===localStorage.searchFulltext,searchContinous:"true"===localStorage.searchContinous},e}return Object(c.a)(n,[{key:"render",value:function(){var e,t=this,n=(this.props.Translations||[]).filter((function(e){var n;if(n=t.state.searchFulltext?(e.key+Object.keys(e.value).map((function(t){return e.value[t].value})).join(" ")).toLowerCase().split("_").join(" "):e.key.toLowerCase().split("_").join(" "),t.state.searchContinous)return n.includes(t.state.search.toLowerCase().split("_").join(" "));var a=t.state.search.split(" ");return a.filter((function(e){return n.split(" ").find((function(t){return t.includes(e)}))})).length===a.length})),a=(null===(e=this.props.Locales)||void 0===e?void 0:e.length)||0;return Object(C.jsxs)("div",{className:"TranslatorSidebar",children:[Object(C.jsxs)("div",{id:"filterBar",children:[Object(C.jsxs)("div",{className:"settingContainer",children:[Object(C.jsxs)("div",{className:"setting",children:[Object(C.jsx)("span",{children:p("search_option_fulltext")}),Object(C.jsx)("input",{type:"checkbox",defaultChecked:"true"===localStorage.searchFulltext,onChange:function(e){localStorage.searchFulltext=e.target.checked,t.setState({searchFulltext:e.target.checked})}})]}),Object(C.jsxs)("div",{className:"setting",children:[Object(C.jsx)("span",{children:p("search_option_continous")}),Object(C.jsx)("input",{type:"checkbox",defaultChecked:"true"===localStorage.searchContinous,onChange:function(e){localStorage.searchContinous=e.target.checked,t.setState({searchContinous:e.target.checked})}})]})]}),Object(C.jsx)("input",{placeholder:"search",autoFocus:!0,onChange:function(e){var a,s,r,i;(t.setState({search:e.target.value}),n[0]&&e.target.value)?null===(a=(s=t.props).OnSelectTranslation)||void 0===a||a.call(s,n[0]):null===(r=(i=t.props).OnSelectTranslation)||void 0===r||r.call(i)}})]}),Object(C.jsx)("div",{id:"menuTree","data-testid":"menuTree",children:n.map((function(e){return Object(C.jsx)("div",{className:"menuEntry ".concat(Object.keys(e.value).filter((function(t){return e.value[t].value})).length<a?"warning":""),onClick:function(){var n,a;null===(n=(a=t.props).OnSelectTranslation)||void 0===n||n.call(a,e)},children:Object(C.jsx)("p",{children:function(){for(var n=[],a=e.key.toLowerCase().split("_").join(" ");a.includes(t.state.search.toLowerCase().split("_").join(" "))&&n.length<10;){var s=a.indexOf(t.state.search.toLowerCase().split("_").join(" "))+n.length*t.state.search.length;n.push({position:s}),a=a.replace(t.state.search.toLowerCase().split("_").join(" "),"")}n=n.map((function(n){var a=e.key.slice(n.position,n.position+t.state.search.length);return Object(S.a)(Object(S.a)({},n),{},{text:a})}));for(var r=[],i=0;i<e.key.length;i++)r.push(e.key[i]);return n.forEach((function(e){for(var t=0;t<e.text.length;t++)r[e.position+t]=Object(C.jsx)("span",{className:"highlight",children:r[e.position+t]},"position".concat(e.position+t))})),r}()})},e.file+e.key)}))})]})}}]),n}(s.a.Component),E=function(e){Object(l.a)(n,e);var t=Object(u.a)(n);function n(){return Object(o.a)(this,n),t.apply(this,arguments)}return Object(c.a)(n,[{key:"render",value:function(){return Object(C.jsxs)("div",{className:"TranslatorBody userManual",children:[Object(C.jsx)("h2",{children:"User manual"}),Object(C.jsx)("p",{children:p("manual_description")}),Object(C.jsx)("h3",{children:p("manual_web_title")}),Object(C.jsx)("p",{children:p("manual_web_1")}),Object(C.jsx)("p",{children:p("manual_web_2")}),Object(C.jsx)("p",{children:p("manual_web_3")}),Object(C.jsx)("h4",{children:p("manual_sidebar_title")}),Object(C.jsx)("p",{children:p("manual_sidebar_1")}),Object(C.jsx)("h4",{children:p("manual_search_title")}),Object(C.jsx)("p",{children:p("manual_search_1")}),Object(C.jsxs)("p",{children:[Object(C.jsx)("b",{children:p("manual_search_fulltext_1")})," ",p("manual_search_fulltext_2")]}),Object(C.jsxs)("p",{children:[Object(C.jsx)("b",{children:p("manual_search_continous_1")})," ",p("manual_search_continous_2")," ",Object(C.jsx)("span",{className:"code",children:p("manual_search_continous_3")})," ",p("manual_search_continous_4")," ",Object(C.jsx)("span",{className:"code",children:p("manual_search_continous_5")})," ",p("manual_search_continous_6")," ",Object(C.jsx)("span",{className:"code",children:p("manual_search_continous_7")})]}),Object(C.jsx)("h3",{children:p("manual_setup_title")}),Object(C.jsxs)("p",{children:[p("manual_setup_1"),Object(C.jsx)("span",{className:"code",children:"npx crowdfree ./src"})," ",p("manual_setup_2")," ",Object(C.jsx)("span",{className:"code",children:"node backend/index.js ../../projectName/src"}),p("manual_setup_3")]}),Object(C.jsxs)("div",{className:"codeBlock code",children:[Object(C.jsx)("p",{children:"locale"}),Object(C.jsxs)("p",{children:["| ","en"]}),Object(C.jsxs)("p",{children:["| ","| ","locale.json"]}),Object(C.jsxs)("p",{children:["| ","no"]}),Object(C.jsxs)("p",{children:["| ","| ","locale.json"]})]}),Object(C.jsx)("p",{children:p("manual_setup_4")}),Object(C.jsxs)("div",{className:"codeBlock code",children:[Object(C.jsx)("p",{children:"{"}),Object(C.jsx)("p",{children:'"company_name": "English doodads company",'}),Object(C.jsx)("p",{children:'"company_description": "Our company creates doodads for customers"'}),Object(C.jsx)("p",{children:"}"})]}),p("manual_setup_5")," ",Object(C.jsx)("span",{className:"code",children:"locale/no/locale.json"})," ",p("manual_setup_6"),Object(C.jsxs)("div",{className:"codeBlock code",children:[Object(C.jsx)("p",{children:"{"}),Object(C.jsx)("p",{children:'"company_name": "Enkelsk duppeditt firma"'}),Object(C.jsx)("p",{children:"}"})]}),p("manual_setup_7")," ",Object(C.jsx)("span",{className:"code",children:"company_name"})," ",p("manual_setup_8")," ",Object(C.jsx)("span",{className:"code",children:"company_description"})," ",p("manual_setup_9"),Object(C.jsxs)("span",{className:"code",children:[p(""),"company_name"]})," ",p("manual_setup_10")," ",Object(C.jsx)("span",{className:"code",children:"company_name"})," ",p("manual_setup_11")]})}}]),n}(s.a.Component),L=function(e){Object(l.a)(n,e);var t=Object(u.a)(n);function n(){var e;return Object(o.a)(this,n),(e=t.call(this)).state={},e}return Object(c.a)(n,[{key:"componentDidMount",value:function(){this.setState({translation:this.props.Translation})}},{key:"componentDidUpdate",value:function(){var e=Object(_.a)(f.a.mark((function e(t){var n,a,s,r,i,o,c,l,u;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=(null===(n=t.Translation)||void 0===n?void 0:n.file)+(null===(a=t.Translation)||void 0===a?void 0:a.key),l=(null===(s=this.props.Translation)||void 0===s?void 0:s.file)+(null===(r=this.props.Translation)||void 0===r?void 0:r.key),!c||this.props.Translation){e.next=6;break}this.setState({translation:void 0}),e.next=19;break;case 6:if(c===l||!this.props.Translation){e.next=18;break}if(this.setState({translation:this.props.Translation,loading:!0}),!this.props.NoNetwork){e.next=12;break}u=this.props.Translation,e.next=15;break;case 12:return e.next=14,w.getTranslation(this.props.Translation.file,this.props.Translation.key);case 14:u=e.sent;case 15:this.setState({translation:u,loading:!1}),e.next=19;break;case 18:JSON.stringify(null===(i=t.Translation)||void 0===i?void 0:i.value)!==JSON.stringify(null===(o=this.props.Translation)||void 0===o?void 0:o.value)&&(console.log("Got update to same translation"),this.setState({translation:this.props.Translation}));case 19:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e=this,t=this.state.translation,n=this.props.Locales||[];return t?Object(C.jsxs)("div",{className:"TranslatorBody",children:[Object(C.jsxs)("h2",{children:[t.file," / ",t.key]}),Object(C.jsx)("p",{}),n.map((function(n){var a,s,r,i,o=n.locale;return Object(C.jsxs)("div",{children:[Object(C.jsxs)("h3",{children:[p("program_locale_prefix")," ",o]}),Object(C.jsx)("textarea",{disabled:e.state.loading,className:"longTextInput",rows:"7",value:(null===(a=t.value[o])||void 0===a?void 0:a.value)||void 0,onChange:function(n){n.target.value?(t.value[o]||(t.value[o]={}),t.value[o].value=n.target.value):t.value[o]="",t.timestamp=Date.now(),e.setState({translation:e.state.translation})},onBlur:function(n){e.props.NoNetwork||w.updateTranslation({file:t.file,key:t.key,locale:o,props:{value:n.target.value}})}}),(null===(s=t.value[o])||void 0===s?void 0:s.suggestions)?Object(C.jsx)("h4",{children:p("program_suggestions_header")}):"",null===(r=t.value[o])||void 0===r||null===(i=r.suggestions)||void 0===i?void 0:i.map((function(e){return Object(C.jsxs)("div",{className:"suggestion",children:[Object(C.jsx)("i",{children:e.type}),Object(C.jsx)("p",{children:e.value})]},e.type+e.lang+e.source)}))]},t.file+t.key+o)})),Object(C.jsx)("button",{children:"+ New translation"})]}):Object(C.jsx)(E,{})}}]),n}(s.a.Component),F=function(e){Object(l.a)(n,e);var t=Object(u.a)(n);function n(){var e;return Object(o.a)(this,n),(e=t.call(this)).state={translations:[]},e}return Object(c.a)(n,[{key:"componentDidMount",value:function(){var e=Object(_.a)(f.a.mark((function e(){var t,n=this;return f.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.getTranslations((function(e){var t=n.state.translations.filter((function(t){return!e.find((function(e){return t.file===e.file}))||!e.find((function(e){return t.key===e.key}))}));e.forEach((function(e){var a=n.state.translations.find((function(t){return e.file===t.file&&e.key===t.key}));if(!a)return console.error(new Error("Updated nonexistant translation, skipping")),!1;!a.timestamp||a.timestamp<=e.timestamp?t.push(e):console.log("Not updating to avoid race condition",a.timestamp,e.timestamp,a,e)})),n.setState({translations:T()(t),activeTranslation:e.find((function(e){return e.file+e.key===n.state.activeTranslation.file+n.state.activeTranslation.key}))||n.state.activeTranslation})}));case 2:return t=e.sent,e.t0=this,e.t1=t,e.next=7,w.getLocales();case 7:e.t2=e.sent,e.t3={translations:e.t1,locales:e.t2},e.t0.setState.call(e.t0,e.t3);case 10:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e=this;return Object(C.jsxs)("div",{id:"translator",style:{width:"100%",height:"calc(100% - 50px)"},children:[Object(C.jsx)(N,{Translations:this.state.translations,Locales:this.state.locales,OnSelectTranslation:function(t){e.setState({activeTranslation:t})}}),Object(C.jsx)(L,{Translation:this.state.activeTranslation,Locales:this.state.locales})]})}}]),n}(s.a.Component),P=function(e){Object(l.a)(n,e);var t=Object(u.a)(n);function n(){return Object(o.a)(this,n),t.apply(this,arguments)}return Object(c.a)(n,[{key:"render",value:function(){return Object(C.jsxs)(C.Fragment,{children:[Object(C.jsx)(D,{}),Object(C.jsx)(F,{})]})}}]),n}(s.a.Component),D=function(e){Object(l.a)(n,e);var t=Object(u.a)(n);function n(){return Object(o.a)(this,n),t.apply(this,arguments)}return Object(c.a)(n,[{key:"render",value:function(){return Object(C.jsx)("div",{id:"header",children:Object(C.jsx)("h1",{children:p("program_title")})})}}]),n}(s.a.Component),B=P,I=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,22)).then((function(t){var n=t.getCLS,a=t.getFID,s=t.getFCP,r=t.getLCP,i=t.getTTFB;n(e),a(e),s(e),r(e),i(e)}))};i.a.render(Object(C.jsx)(s.a.StrictMode,{children:Object(C.jsx)(B,{})}),document.getElementById("root")),I()}},[[21,1,2]]]);
//# sourceMappingURL=main.01828a48.chunk.js.map