v1.0.0
This commit is contained in:
commit
a157afe625
21 changed files with 4623 additions and 0 deletions
674
LICENSE
Normal file
674
LICENSE
Normal file
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
78
assets/css/editor.css
Normal file
78
assets/css/editor.css
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* AI Translator (by ROBOTSTXT) — editor styles.
|
||||
*
|
||||
* Scoped to the Classic metabox and the Block editor sidebar panel.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
.ai-translator-classic select,
|
||||
.ai-translator-classic .button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ai-translator-classic .ai-translator-status {
|
||||
margin-top: 8px;
|
||||
padding: 6px 8px;
|
||||
min-height: 1.5em;
|
||||
font-size: 12px;
|
||||
border-left: 3px solid transparent;
|
||||
background: transparent;
|
||||
color: #50575e;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.ai-translator-classic .ai-translator-status--busy {
|
||||
border-color: #2271b1;
|
||||
background: #f0f6fc;
|
||||
color: #2271b1;
|
||||
}
|
||||
|
||||
.ai-translator-classic .ai-translator-status--busy::before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
margin-right: 6px;
|
||||
border: 2px solid #2271b1;
|
||||
border-top-color: transparent;
|
||||
border-radius: 50%;
|
||||
animation: ai-translator-spin 0.8s linear infinite;
|
||||
vertical-align: -2px;
|
||||
}
|
||||
|
||||
.ai-translator-classic .ai-translator-status--success {
|
||||
border-color: #008a20;
|
||||
background: #edfaef;
|
||||
color: #008a20;
|
||||
}
|
||||
|
||||
.ai-translator-classic .ai-translator-status--warning {
|
||||
border-color: #dba617;
|
||||
background: #fcf9e8;
|
||||
color: #80651e;
|
||||
}
|
||||
|
||||
.ai-translator-classic .ai-translator-status--error {
|
||||
border-color: #d63638;
|
||||
background: #fcf0f1;
|
||||
color: #d63638;
|
||||
}
|
||||
|
||||
@keyframes ai-translator-spin {
|
||||
to {
|
||||
transform: rotate( 360deg );
|
||||
}
|
||||
}
|
||||
|
||||
.ai-translator-sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.ai-translator-sidebar .components-notice {
|
||||
margin: 0;
|
||||
}
|
||||
389
assets/js/editor.js
Normal file
389
assets/js/editor.js
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
/**
|
||||
* AI Translator (by ROBOTSTXT) — editor UI.
|
||||
*
|
||||
* Adds a translation panel to the Block editor sidebar and a handler for the
|
||||
* Classic editor metabox. Both implementations share the same REST endpoint
|
||||
* and language list.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
function warn( message ) {
|
||||
if ( window.console && typeof window.console.warn === 'function' ) {
|
||||
window.console.warn( '[AI Translator] ' + message );
|
||||
}
|
||||
}
|
||||
|
||||
var data = window.aiTranslatorData;
|
||||
|
||||
if ( ! data ) {
|
||||
warn( 'window.aiTranslatorData is missing; aborting.' );
|
||||
return;
|
||||
}
|
||||
|
||||
var apiFetch = window.wp && window.wp.apiFetch ? window.wp.apiFetch : null;
|
||||
var labels = data.i18n || {};
|
||||
|
||||
/**
|
||||
* Calls the REST endpoint to translate the selected fields of the saved post.
|
||||
*
|
||||
* @param {Array<string>} fields Field names to translate ('title', 'content').
|
||||
* @param {string} targetLocale WordPress locale code.
|
||||
* @returns {Promise<Object>} Promise resolving to the translated values.
|
||||
*/
|
||||
function requestTranslation( fields, targetLocale ) {
|
||||
if ( ! apiFetch ) {
|
||||
return Promise.reject( new Error( labels.genericError || 'Translation failed.' ) );
|
||||
}
|
||||
|
||||
return apiFetch( {
|
||||
path: '/' + data.restNamespace + data.restRoute,
|
||||
method: 'POST',
|
||||
data: {
|
||||
post_id: data.postId,
|
||||
fields: fields,
|
||||
target_locale: targetLocale,
|
||||
},
|
||||
} );
|
||||
}
|
||||
|
||||
function resolveFields( wantTitle, wantContent ) {
|
||||
var fields = [];
|
||||
if ( wantTitle && data.settings.translateTitle ) {
|
||||
fields.push( 'title' );
|
||||
}
|
||||
if ( wantContent && data.settings.translateContent ) {
|
||||
fields.push( 'content' );
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
function describeError( error ) {
|
||||
if ( error && typeof error.message === 'string' && error.message ) {
|
||||
return error.message;
|
||||
}
|
||||
return labels.genericError || 'Translation failed.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a translation response using the right method for the current editor.
|
||||
*
|
||||
* In the block editor, uses wp.data dispatch (and wp.blocks.parse for content).
|
||||
* In the classic editor, updates the DOM directly (title input + TinyMCE).
|
||||
*
|
||||
* @param {Object} response Translation response.
|
||||
* @param {Document} doc Document where the metabox lives (for classic fallback).
|
||||
*/
|
||||
function applyTranslationResult( response, doc ) {
|
||||
var wp = window.wp || {};
|
||||
var isBlockCtx = data.context === 'block' && wp.data && wp.data.dispatch;
|
||||
|
||||
if ( isBlockCtx ) {
|
||||
if ( response.title !== undefined ) {
|
||||
wp.data.dispatch( 'core/editor' ).editPost( { title: response.title } );
|
||||
}
|
||||
if ( response.content !== undefined ) {
|
||||
if ( wp.blocks && typeof wp.blocks.parse === 'function' ) {
|
||||
var blocks = wp.blocks.parse( response.content );
|
||||
var blockEd = wp.data.dispatch( 'core/block-editor' );
|
||||
if ( blockEd && typeof blockEd.resetBlocks === 'function' ) {
|
||||
blockEd.resetBlocks( blocks );
|
||||
} else {
|
||||
wp.data.dispatch( 'core/editor' ).editPost( { content: response.content } );
|
||||
}
|
||||
} else {
|
||||
wp.data.dispatch( 'core/editor' ).editPost( { content: response.content } );
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
doc = doc || document;
|
||||
if ( response.title !== undefined ) {
|
||||
var titleInput = doc.getElementById( 'title' );
|
||||
if ( titleInput ) {
|
||||
titleInput.value = response.title;
|
||||
}
|
||||
}
|
||||
if ( response.content !== undefined ) {
|
||||
applyContentToClassic( response.content, doc );
|
||||
}
|
||||
}
|
||||
|
||||
function applyContentToClassic( content, doc ) {
|
||||
doc = doc || document;
|
||||
var textarea = doc.getElementById( 'content' );
|
||||
if ( textarea ) {
|
||||
textarea.value = content;
|
||||
}
|
||||
if ( window.tinymce && typeof window.tinymce.get === 'function' ) {
|
||||
var editor = window.tinymce.get( 'content' );
|
||||
if ( editor && typeof editor.setContent === 'function' ) {
|
||||
editor.setContent( content );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Classic editor integration (metabox).
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function initClassicEditor() {
|
||||
var container = document.getElementById( 'ai-translator-classic' );
|
||||
if ( ! container ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var button = document.getElementById( 'ai-translator-classic-button' );
|
||||
var select = document.getElementById( 'ai-translator-locale' );
|
||||
var status = document.getElementById( 'ai-translator-classic-status' );
|
||||
|
||||
if ( ! button || ! select ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function setStatus( text, kind ) {
|
||||
if ( ! status ) {
|
||||
return;
|
||||
}
|
||||
status.textContent = text;
|
||||
status.className = 'ai-translator-status' + ( kind ? ' ai-translator-status--' + kind : '' );
|
||||
}
|
||||
|
||||
button.addEventListener( 'click', function () {
|
||||
var locale = select.value;
|
||||
if ( ! locale ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var fields = resolveFields( data.settings.translateTitle, data.settings.translateContent );
|
||||
if ( fields.length === 0 ) {
|
||||
setStatus( labels.noFields || '', 'warning' );
|
||||
return;
|
||||
}
|
||||
|
||||
button.disabled = true;
|
||||
button.dataset.busy = '1';
|
||||
setStatus( labels.translating || 'Translating…', 'busy' );
|
||||
|
||||
requestTranslation( fields, locale )
|
||||
.then( function ( response ) {
|
||||
applyTranslationResult( response, document );
|
||||
setStatus( labels.success || 'Translation applied.', 'success' );
|
||||
} )
|
||||
.catch( function ( error ) {
|
||||
setStatus( describeError( error ), 'error' );
|
||||
} )
|
||||
.then( function () {
|
||||
button.disabled = false;
|
||||
button.dataset.busy = '0';
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Block editor integration (PluginSidebar).
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
function initBlockEditor() {
|
||||
var wp = window.wp || {};
|
||||
|
||||
if ( ! wp.plugins || ! wp.element || ! wp.components || ! wp.data || ! wp.editor || ! wp.editor.PluginSidebar ) {
|
||||
warn( 'Block editor APIs not available; skipping sidebar registration.' );
|
||||
return;
|
||||
}
|
||||
|
||||
var el = wp.element.createElement;
|
||||
var Fragment = wp.element.Fragment;
|
||||
var useState = wp.element.useState;
|
||||
var registerP = wp.plugins.registerPlugin;
|
||||
var sidebar = wp.editor.PluginSidebar;
|
||||
var menuItem = wp.editor.PluginSidebarMoreMenuItem;
|
||||
var components = wp.components;
|
||||
var dataStore = wp.data;
|
||||
|
||||
function applyNoticeSnackbar( status, message ) {
|
||||
if ( ! dataStore || ! dataStore.dispatch || ! message ) {
|
||||
return;
|
||||
}
|
||||
var noticesStore = dataStore.dispatch( 'core/notices' );
|
||||
if ( ! noticesStore || typeof noticesStore.createNotice !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
noticesStore.createNotice(
|
||||
status,
|
||||
message,
|
||||
{
|
||||
type: 'snackbar',
|
||||
isDismissible: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function Panel() {
|
||||
var localeState = useState( ( data.languages && data.languages[0] ) ? data.languages[0].locale : '' );
|
||||
var locale = localeState[0];
|
||||
var setLocale = localeState[1];
|
||||
|
||||
var busyState = useState( false );
|
||||
var busy = busyState[0];
|
||||
var setBusy = busyState[1];
|
||||
|
||||
var noticeState = useState( null );
|
||||
var notice = noticeState[0];
|
||||
var setNotice = noticeState[1];
|
||||
|
||||
var titleState = useState( !! data.settings.translateTitle );
|
||||
var translateTitle = titleState[0];
|
||||
var setTranslateTitle = titleState[1];
|
||||
|
||||
var contentState = useState( !! data.settings.translateContent );
|
||||
var translateContent = contentState[0];
|
||||
var setTranslateContent = contentState[1];
|
||||
|
||||
var coreEditor = dataStore.select( 'core/editor' );
|
||||
var isDirty = coreEditor && typeof coreEditor.isEditedPostDirty === 'function' ? coreEditor.isEditedPostDirty() : false;
|
||||
|
||||
if ( ! data.available ) {
|
||||
return el( 'div', { className: 'ai-translator-sidebar' },
|
||||
el( components.Notice, { status: 'warning', isDismissible: false }, labels.aiUnavailable || '' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! data.settings.translateTitle && ! data.settings.translateContent ) {
|
||||
return el( 'div', { className: 'ai-translator-sidebar' },
|
||||
el( components.Notice, { status: 'info', isDismissible: false }, labels.noFields || '' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! data.languages || data.languages.length === 0 ) {
|
||||
return el( 'div', { className: 'ai-translator-sidebar' },
|
||||
el( components.Notice, { status: 'info', isDismissible: false }, labels.noLanguages || '' )
|
||||
);
|
||||
}
|
||||
|
||||
var options = data.languages.map( function ( language ) {
|
||||
return { value: language.locale, label: language.name };
|
||||
} );
|
||||
|
||||
function runTranslate() {
|
||||
var fields = resolveFields( translateTitle, translateContent );
|
||||
|
||||
if ( fields.length === 0 ) {
|
||||
setNotice( { status: 'warning', message: labels.noFields || '' } );
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy( true );
|
||||
setNotice( null );
|
||||
applyNoticeSnackbar( 'info', labels.translating || 'Translating…' );
|
||||
|
||||
requestTranslation( fields, locale )
|
||||
.then( function ( response ) {
|
||||
applyTranslationResult( response );
|
||||
setNotice( { status: 'success', message: labels.success || '' } );
|
||||
applyNoticeSnackbar( 'success', labels.success || 'Translation applied.' );
|
||||
} )
|
||||
.catch( function ( error ) {
|
||||
var errorMessage = describeError( error );
|
||||
setNotice( { status: 'error', message: errorMessage } );
|
||||
applyNoticeSnackbar( 'error', errorMessage );
|
||||
} )
|
||||
.then( function () {
|
||||
setBusy( false );
|
||||
} );
|
||||
}
|
||||
|
||||
var children = [];
|
||||
|
||||
if ( isDirty ) {
|
||||
children.push( el( components.Notice, {
|
||||
status: 'warning',
|
||||
isDismissible: false,
|
||||
key: 'dirty',
|
||||
}, labels.saveBeforeWarn || '' ) );
|
||||
}
|
||||
|
||||
if ( notice ) {
|
||||
children.push( el( components.Notice, {
|
||||
status: notice.status,
|
||||
isDismissible: true,
|
||||
onRemove: function () {
|
||||
setNotice( null );
|
||||
},
|
||||
key: 'notice',
|
||||
}, notice.message ) );
|
||||
}
|
||||
|
||||
children.push( el( components.SelectControl, {
|
||||
key: 'locale',
|
||||
label: labels.targetLanguage || '',
|
||||
value: locale,
|
||||
options: options,
|
||||
onChange: function ( value ) {
|
||||
setLocale( value );
|
||||
},
|
||||
} ) );
|
||||
|
||||
if ( data.settings.translateTitle ) {
|
||||
children.push( el( components.CheckboxControl, {
|
||||
key: 'title',
|
||||
label: labels.translateTitle || '',
|
||||
checked: translateTitle,
|
||||
onChange: function ( value ) {
|
||||
setTranslateTitle( !! value );
|
||||
},
|
||||
} ) );
|
||||
}
|
||||
|
||||
if ( data.settings.translateContent ) {
|
||||
children.push( el( components.CheckboxControl, {
|
||||
key: 'content',
|
||||
label: labels.translateContent || '',
|
||||
checked: translateContent,
|
||||
onChange: function ( value ) {
|
||||
setTranslateContent( !! value );
|
||||
},
|
||||
} ) );
|
||||
}
|
||||
|
||||
children.push( el( components.Button, {
|
||||
key: 'submit',
|
||||
variant: 'primary',
|
||||
disabled: busy || ! locale,
|
||||
isBusy: busy,
|
||||
onClick: runTranslate,
|
||||
}, busy ? ( labels.translating || '' ) : ( labels.translate || '' ) ) );
|
||||
|
||||
return el( 'div', { className: 'ai-translator-sidebar' }, children );
|
||||
}
|
||||
|
||||
registerP( 'ai-translator', {
|
||||
render: function () {
|
||||
return el( Fragment, null,
|
||||
menuItem ? el( menuItem, { target: 'ai-translator', icon: 'translation' }, labels.panelTitle || '' ) : null,
|
||||
el( sidebar, { name: 'ai-translator', title: labels.panelTitle || '', icon: 'translation' },
|
||||
el( components.PanelBody, {}, el( Panel ) )
|
||||
)
|
||||
);
|
||||
},
|
||||
} );
|
||||
}
|
||||
|
||||
function start() {
|
||||
if ( data.context === 'block' ) {
|
||||
initBlockEditor();
|
||||
} else {
|
||||
initClassicEditor();
|
||||
}
|
||||
}
|
||||
|
||||
if ( document.readyState === 'loading' ) {
|
||||
document.addEventListener( 'DOMContentLoaded', start );
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
} )();
|
||||
32
changelog.txt
Normal file
32
changelog.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
== Changelog ==
|
||||
|
||||
= 1.0.0 =
|
||||
|
||||
_Release date: 2026-05-23_
|
||||
|
||||
**Highlights**
|
||||
|
||||
* Initial release of AI Translator (by ROBOTSTXT).
|
||||
* Translates post title and content from the editor using the official WordPress AI plugin as backend.
|
||||
* Multisite-ready with global or per-site configuration.
|
||||
|
||||
**Added**
|
||||
|
||||
* Block editor sidebar panel and Classic editor metabox with target-language selector and a Translate button.
|
||||
* REST endpoint `POST /wp-json/ai-translator/v1/translate` for editor and external integrations.
|
||||
* WP-CLI command `wp ai-translator translate` for single-post and bulk translation.
|
||||
* Network admin settings page with global / per-site mode toggle.
|
||||
* Site admin settings page with title and content translation toggles.
|
||||
* Model recommendations table in the settings pages as guidance.
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 7.0
|
||||
* PHP: 7.4 - 8.5
|
||||
* WP-CLI: 2.10 or newer
|
||||
|
||||
**Tests**
|
||||
|
||||
* PHP Coding Standards: WordPress-Core, WordPress-Docs, WordPress-Extra
|
||||
* PHPCompatibility: 7.4 - 8.5
|
||||
* PHPStan: level 9
|
||||
530
includes/class-ai-translator-admin.php
Normal file
530
includes/class-ai-translator-admin.php
Normal file
|
|
@ -0,0 +1,530 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin pages and form handling for the AI Translator plugin.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'AI_Translator_Admin' ) ) {
|
||||
|
||||
/**
|
||||
* Registers the settings pages and handles form submissions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class AI_Translator_Admin {
|
||||
|
||||
/**
|
||||
* Menu slug used in single-site and Multisite per-site admin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const SITE_MENU_SLUG = 'ai-translator-settings';
|
||||
|
||||
/**
|
||||
* Menu slug used in Multisite network admin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const NETWORK_MENU_SLUG = 'ai-translator-network-settings';
|
||||
|
||||
/**
|
||||
* Nonce action for the site form.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const NONCE_SITE = 'ai_translator_site_save';
|
||||
|
||||
/**
|
||||
* Nonce action for the network form.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const NONCE_NETWORK = 'ai_translator_network_save';
|
||||
|
||||
/**
|
||||
* Settings handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var AI_Translator_Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param AI_Translator_Settings $settings Settings handler.
|
||||
*/
|
||||
public function __construct( AI_Translator_Settings $settings ) {
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers WordPress hooks.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
add_action( 'admin_menu', array( $this, 'register_site_menu' ) );
|
||||
add_action( 'admin_post_ai_translator_save_site', array( $this, 'handle_site_save' ) );
|
||||
|
||||
if ( is_multisite() ) {
|
||||
add_action( 'network_admin_menu', array( $this, 'register_network_menu' ) );
|
||||
add_action( 'network_admin_edit_ai_translator_save_network', array( $this, 'handle_network_save' ) );
|
||||
}
|
||||
|
||||
add_filter( 'plugin_action_links_' . AI_TRANSLATOR_BASENAME, array( $this, 'add_settings_link' ) );
|
||||
|
||||
if ( is_multisite() ) {
|
||||
add_filter( 'network_admin_plugin_action_links_' . AI_TRANSLATOR_BASENAME, array( $this, 'add_network_settings_link' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the site-level settings page.
|
||||
*
|
||||
* Hidden in Multisite when the network mode is 'global', because the global
|
||||
* settings live in the network admin in that case.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_site_menu() {
|
||||
if ( is_multisite() && 'global' === $this->settings->get_network_mode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_options_page(
|
||||
__( 'AI Translator', 'robotstxt-ai-translator' ),
|
||||
__( 'AI Translator', 'robotstxt-ai-translator' ),
|
||||
'manage_options',
|
||||
self::SITE_MENU_SLUG,
|
||||
array( $this, 'render_site_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the network-level settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_network_menu() {
|
||||
add_submenu_page(
|
||||
'settings.php',
|
||||
__( 'AI Translator', 'robotstxt-ai-translator' ),
|
||||
__( 'AI Translator', 'robotstxt-ai-translator' ),
|
||||
'manage_network_options',
|
||||
self::NETWORK_MENU_SLUG,
|
||||
array( $this, 'render_network_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a settings link in the site plugin list.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<int,string> $links Existing action links.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function add_settings_link( $links ) {
|
||||
if ( is_multisite() && 'global' === $this->settings->get_network_mode() ) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
$url = admin_url( 'options-general.php?page=' . self::SITE_MENU_SLUG );
|
||||
$label = esc_html__( 'Settings', 'robotstxt-ai-translator' );
|
||||
|
||||
array_unshift( $links, '<a href="' . esc_url( $url ) . '">' . $label . '</a>' );
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a settings link in the network plugin list.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<int,string> $links Existing action links.
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function add_network_settings_link( $links ) {
|
||||
$url = network_admin_url( 'settings.php?page=' . self::NETWORK_MENU_SLUG );
|
||||
$label = esc_html__( 'Settings', 'robotstxt-ai-translator' );
|
||||
|
||||
array_unshift( $links, '<a href="' . esc_url( $url ) . '">' . $label . '</a>' );
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the site-level settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_site_page() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to access this page.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
$current = $this->settings->get_site_settings();
|
||||
$defaults = is_multisite() ? $this->settings->get_network_settings() : array();
|
||||
$updated = 1 === filter_input( INPUT_GET, 'updated', FILTER_VALIDATE_INT );
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html__( 'AI Translator Settings', 'robotstxt-ai-translator' ); ?></h1>
|
||||
|
||||
<?php if ( $updated ) : ?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><?php echo esc_html__( 'Settings saved.', 'robotstxt-ai-translator' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
||||
<input type="hidden" name="action" value="ai_translator_save_site" />
|
||||
<?php wp_nonce_field( self::NONCE_SITE ); ?>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html__( 'Translation fields', 'robotstxt-ai-translator' ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html__( 'Translation fields', 'robotstxt-ai-translator' ); ?></legend>
|
||||
|
||||
<label for="ai-translator-translate-title">
|
||||
<input type="checkbox" id="ai-translator-translate-title" name="ai_translator_settings[translate_title]" value="1" <?php checked( $current['translate_title'] ); ?> />
|
||||
<?php echo esc_html__( 'Translate title', 'robotstxt-ai-translator' ); ?>
|
||||
</label><br />
|
||||
|
||||
<label for="ai-translator-translate-content">
|
||||
<input type="checkbox" id="ai-translator-translate-content" name="ai_translator_settings[translate_content]" value="1" <?php checked( $current['translate_content'] ); ?> />
|
||||
<?php echo esc_html__( 'Translate content', 'robotstxt-ai-translator' ); ?>
|
||||
</label>
|
||||
|
||||
<?php if ( is_multisite() ) : ?>
|
||||
<p class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: title default, 2: content default. */
|
||||
esc_html__( 'Network defaults: title %1$s, content %2$s.', 'robotstxt-ai-translator' ),
|
||||
isset( $defaults['translate_title'] ) && $defaults['translate_title'] ? esc_html__( 'enabled', 'robotstxt-ai-translator' ) : esc_html__( 'disabled', 'robotstxt-ai-translator' ),
|
||||
isset( $defaults['translate_content'] ) && $defaults['translate_content'] ? esc_html__( 'enabled', 'robotstxt-ai-translator' ) : esc_html__( 'disabled', 'robotstxt-ai-translator' )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
|
||||
<?php $this->render_model_recommendations(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the network-level settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_network_page() {
|
||||
if ( ! current_user_can( 'manage_network_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to access this page.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
$mode = $this->settings->get_network_mode();
|
||||
$network = $this->settings->get_network_settings();
|
||||
$updated = 1 === filter_input( INPUT_GET, 'updated', FILTER_VALIDATE_INT );
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html__( 'AI Translator Network Settings', 'robotstxt-ai-translator' ); ?></h1>
|
||||
|
||||
<?php if ( $updated ) : ?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><?php echo esc_html__( 'Network settings saved.', 'robotstxt-ai-translator' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?php echo esc_url( network_admin_url( 'edit.php?action=ai_translator_save_network' ) ); ?>">
|
||||
<?php wp_nonce_field( self::NONCE_NETWORK ); ?>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html__( 'Configuration mode', 'robotstxt-ai-translator' ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html__( 'Configuration mode', 'robotstxt-ai-translator' ); ?></legend>
|
||||
|
||||
<label>
|
||||
<input type="radio" name="ai_translator_mode" value="global" <?php checked( 'global', $mode ); ?> />
|
||||
<?php echo esc_html__( 'Global configuration: a single setting applies to every site.', 'robotstxt-ai-translator' ); ?>
|
||||
</label><br />
|
||||
|
||||
<label>
|
||||
<input type="radio" name="ai_translator_mode" value="per-site" <?php checked( 'per-site', $mode ); ?> />
|
||||
<?php echo esc_html__( 'Per-site configuration: each site can override these defaults.', 'robotstxt-ai-translator' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<?php echo esc_html__( 'Translation fields', 'robotstxt-ai-translator' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html__( 'Translation fields', 'robotstxt-ai-translator' ); ?></legend>
|
||||
|
||||
<label for="ai-translator-net-translate-title">
|
||||
<input type="checkbox" id="ai-translator-net-translate-title" name="ai_translator_settings[translate_title]" value="1" <?php checked( $network['translate_title'] ); ?> />
|
||||
<?php echo esc_html__( 'Translate title', 'robotstxt-ai-translator' ); ?>
|
||||
</label><br />
|
||||
|
||||
<label for="ai-translator-net-translate-content">
|
||||
<input type="checkbox" id="ai-translator-net-translate-content" name="ai_translator_settings[translate_content]" value="1" <?php checked( $network['translate_content'] ); ?> />
|
||||
<?php echo esc_html__( 'Translate content', 'robotstxt-ai-translator' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_html__( 'In global mode this is the configuration for the whole network. In per-site mode these values are used as defaults for sites that have not been configured individually.', 'robotstxt-ai-translator' ); ?>
|
||||
</p>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
|
||||
<?php $this->render_model_recommendations(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the site-level form submission.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_site_save() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to perform this action.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( self::NONCE_SITE );
|
||||
|
||||
$raw = isset( $_POST['ai_translator_settings'] ) && is_array( $_POST['ai_translator_settings'] )
|
||||
? wp_unslash( $_POST['ai_translator_settings'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitised by sanitize_settings() below.
|
||||
: array();
|
||||
|
||||
$this->settings->update_site_settings( $this->sanitize_settings( $raw ) );
|
||||
|
||||
$redirect = add_query_arg(
|
||||
array(
|
||||
'page' => self::SITE_MENU_SLUG,
|
||||
'updated' => 1,
|
||||
),
|
||||
admin_url( 'options-general.php' )
|
||||
);
|
||||
|
||||
wp_safe_redirect( $redirect );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the network-level form submission.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_network_save() {
|
||||
if ( ! current_user_can( 'manage_network_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to perform this action.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( self::NONCE_NETWORK );
|
||||
|
||||
$mode_raw = filter_input( INPUT_POST, 'ai_translator_mode', FILTER_UNSAFE_RAW );
|
||||
$raw_mode = is_string( $mode_raw ) ? sanitize_key( $mode_raw ) : 'global';
|
||||
$mode = in_array( $raw_mode, array( 'global', 'per-site' ), true ) ? $raw_mode : 'global';
|
||||
|
||||
$this->settings->update_network_mode( $mode );
|
||||
|
||||
$raw = isset( $_POST['ai_translator_settings'] ) && is_array( $_POST['ai_translator_settings'] )
|
||||
? wp_unslash( $_POST['ai_translator_settings'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitised by sanitize_settings() below.
|
||||
: array();
|
||||
|
||||
$this->settings->update_network_settings( $this->sanitize_settings( $raw ) );
|
||||
|
||||
$redirect = add_query_arg(
|
||||
array(
|
||||
'page' => self::NETWORK_MENU_SLUG,
|
||||
'updated' => 1,
|
||||
),
|
||||
network_admin_url( 'settings.php' )
|
||||
);
|
||||
|
||||
wp_safe_redirect( $redirect );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the model recommendations table.
|
||||
*
|
||||
* Displayed below both the site and network settings pages as guidance for
|
||||
* choosing a provider in the WordPress AI plugin. Purely informational; the
|
||||
* table is not interactive and stores no data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_model_recommendations() {
|
||||
$rows = $this->get_model_recommendations();
|
||||
|
||||
?>
|
||||
<h2><?php echo esc_html__( 'Recommended models', 'robotstxt-ai-translator' ); ?></h2>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_html__( 'This plugin does not call AI providers directly. Configure your preferred provider in the WordPress AI plugin settings. The table below is a guide to help you pick a model based on your translation use case.', 'robotstxt-ai-translator' ); ?>
|
||||
</p>
|
||||
|
||||
<table class="widefat striped ai-translator-recommendations">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php echo esc_html__( 'Use case', 'robotstxt-ai-translator' ); ?></th>
|
||||
<th scope="col"><?php echo esc_html__( 'Recommended model', 'robotstxt-ai-translator' ); ?></th>
|
||||
<th scope="col"><?php echo esc_html__( 'Why', 'robotstxt-ai-translator' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $rows as $row ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( $row['use_case'] ); ?></th>
|
||||
<td><?php echo esc_html( $row['model'] ); ?></td>
|
||||
<td><?php echo esc_html( $row['reason'] ); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_html__( 'These recommendations are based on public benchmarks and community feedback as of the plugin release date. They may change as providers update their models.', 'robotstxt-ai-translator' ); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the model recommendations table data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array<int,array{use_case:string,model:string,reason:string}>
|
||||
*/
|
||||
private function get_model_recommendations() {
|
||||
$rows = array(
|
||||
array(
|
||||
'use_case' => __( 'European languages (ES, CA, FR, DE, IT, PT)', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'DeepL API Pro', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'Best fluency and naturalness (92/100 in benchmarks). Formality control and custom glossaries.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'Asian languages (ZH, JA, KO)', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'GPT-4o / GPT-5 or Claude Sonnet 4', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'Better handling of implicit subjects, honorifics, and cultural references. DeepL falls behind here.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'Marketing / brand tone', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'Claude Sonnet 4 / Opus 4', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'Better preservation of tone, brand voice, and nuance. Ideal for creative copy.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'Technical documentation / code', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'GPT-4o / GPT-5', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'Higher accuracy with variables, structured formats, and technical terminology.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'Long documents (100+ pages)', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'Gemini 2.5 Pro', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( '1M token context window. Maintains terminological consistency across long texts.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'High volume / low cost', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'DeepSeek-V3', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'Quality comparable to GPT-5 at ~$0.14/M tokens (20-50x cheaper than Claude/GPT).', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'Rare / indigenous languages', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'Claude Sonnet or Taskade Translate (multi-model routing)', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'Better coverage for uncommon language pairs.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
array(
|
||||
'use_case' => __( 'Maximum coverage (133+ languages)', 'robotstxt-ai-translator' ),
|
||||
'model' => __( 'Google Cloud Translation', 'robotstxt-ai-translator' ),
|
||||
'reason' => __( 'The most complete option, though with slightly lower quality on European languages.', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the model recommendations shown in the settings pages.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<int,array{use_case:string,model:string,reason:string}> $rows Recommendation rows.
|
||||
*/
|
||||
return (array) apply_filters( 'ai_translator_model_recommendations', $rows );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitises a raw settings array into a strict boolean schema.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<string,mixed> $raw Raw input from the form.
|
||||
*
|
||||
* @return array<string,bool>
|
||||
*/
|
||||
private function sanitize_settings( array $raw ) {
|
||||
return array(
|
||||
'translate_title' => ! empty( $raw['translate_title'] ),
|
||||
'translate_content' => ! empty( $raw['translate_content'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
238
includes/class-ai-translator-cli.php
Normal file
238
includes/class-ai-translator-cli.php
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
/**
|
||||
* WP-CLI commands for the AI Translator plugin.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'AI_Translator_CLI' ) ) {
|
||||
|
||||
/**
|
||||
* Translate posts from the command line.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* # Translate a single post to Spanish.
|
||||
* $ wp ai-translator translate --post-id=42 --locale=es_ES
|
||||
*
|
||||
* # Translate every post of a given type, preview only.
|
||||
* $ wp ai-translator translate --post-type=post --locale=fr_FR --dry-run
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class AI_Translator_CLI {
|
||||
|
||||
/**
|
||||
* Settings handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var AI_Translator_Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Translator handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var AI_Translator_Translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param AI_Translator_Settings $settings Settings handler.
|
||||
* @param AI_Translator_Translator $translator Translator handler.
|
||||
*/
|
||||
public function __construct( AI_Translator_Settings $settings, AI_Translator_Translator $translator ) {
|
||||
$this->settings = $settings;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the command with WP-CLI.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
if ( ! class_exists( 'WP_CLI' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
WP_CLI::add_command( 'ai-translator', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates one or more posts to a target locale.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* --locale=<locale>
|
||||
* : WordPress locale to translate to. Must be installed on the site.
|
||||
*
|
||||
* [--post-id=<id>]
|
||||
* : ID of a single post to translate. Mutually exclusive with --post-type.
|
||||
*
|
||||
* [--post-type=<type>]
|
||||
* : Post type to translate in bulk. Defaults to 'post' when --post-id is omitted.
|
||||
*
|
||||
* [--status=<status>]
|
||||
* : Post status filter when running in bulk mode. Default: 'publish'.
|
||||
*
|
||||
* [--limit=<n>]
|
||||
* : Maximum number of posts to process when running in bulk mode. Default: 50.
|
||||
*
|
||||
* [--dry-run]
|
||||
* : Show what would be translated without calling the AI provider and without writing to the database.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp ai-translator translate --post-id=42 --locale=es_ES
|
||||
* wp ai-translator translate --post-type=page --locale=fr_FR --limit=10 --dry-run
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<int,string> $args Positional arguments (unused).
|
||||
* @param array<string,string> $assoc_args Associative arguments.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translate( $args, $assoc_args ) {
|
||||
unset( $args );
|
||||
|
||||
$locale = isset( $assoc_args['locale'] ) ? (string) $assoc_args['locale'] : '';
|
||||
$dry_run = isset( $assoc_args['dry-run'] );
|
||||
$post_id = isset( $assoc_args['post-id'] ) ? (int) $assoc_args['post-id'] : 0;
|
||||
$type = isset( $assoc_args['post-type'] ) ? (string) $assoc_args['post-type'] : '';
|
||||
$status = isset( $assoc_args['status'] ) ? (string) $assoc_args['status'] : 'publish';
|
||||
$limit = isset( $assoc_args['limit'] ) ? max( 1, (int) $assoc_args['limit'] ) : 50;
|
||||
|
||||
if ( '' === $locale ) {
|
||||
WP_CLI::error( __( 'The --locale flag is required.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( $post_id > 0 && '' !== $type ) {
|
||||
WP_CLI::error( __( 'The --post-id and --post-type flags are mutually exclusive.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
if ( ! $current_user || 0 === (int) $current_user->ID ) {
|
||||
WP_CLI::warning( __( 'No user context. Pass --user=<id|login> so post updates carry an author and capability checks apply.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! $dry_run && ! $this->translator->is_available() ) {
|
||||
WP_CLI::error( __( 'The WordPress AI plugin is not active.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! $dry_run && ! $this->translator->is_supported() ) {
|
||||
WP_CLI::error( __( 'The WordPress AI plugin has no provider configured for text generation.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! in_array( $locale, $this->translator->get_installed_locales(), true ) ) {
|
||||
WP_CLI::error(
|
||||
sprintf(
|
||||
/* translators: %s: locale code. */
|
||||
__( 'The locale %s is not installed on this site.', 'robotstxt-ai-translator' ),
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$settings = $this->settings->get_settings();
|
||||
|
||||
if ( empty( $settings['translate_title'] ) && empty( $settings['translate_content'] ) ) {
|
||||
WP_CLI::error( __( 'No translation fields are enabled in the plugin settings.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( $post_id > 0 ) {
|
||||
$posts = array( get_post( $post_id ) );
|
||||
} else {
|
||||
$type = '' !== $type ? $type : 'post';
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => $type,
|
||||
'post_status' => $status,
|
||||
'numberposts' => $limit,
|
||||
'ignore_sticky_posts' => true,
|
||||
'suppress_filters' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$posts = array_filter(
|
||||
$posts,
|
||||
static function ( $post ) {
|
||||
return $post instanceof WP_Post;
|
||||
}
|
||||
);
|
||||
|
||||
if ( empty( $posts ) ) {
|
||||
WP_CLI::warning( __( 'No posts matched the given criteria.', 'robotstxt-ai-translator' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
$successes = 0;
|
||||
$failures = 0;
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
if ( $dry_run ) {
|
||||
WP_CLI::log( sprintf( '[dry-run] would translate post #%d (%s) to %s.', $post->ID, $post->post_title, $locale ) );
|
||||
++$successes;
|
||||
continue;
|
||||
}
|
||||
|
||||
$update = array( 'ID' => $post->ID );
|
||||
|
||||
if ( ! empty( $settings['translate_title'] ) ) {
|
||||
$translated_title = $this->translator->translate( $post->post_title, $locale );
|
||||
if ( is_wp_error( $translated_title ) ) {
|
||||
WP_CLI::warning( sprintf( '#%d title: %s', $post->ID, $translated_title->get_error_message() ) );
|
||||
++$failures;
|
||||
continue;
|
||||
}
|
||||
$update['post_title'] = $translated_title;
|
||||
}
|
||||
|
||||
if ( ! empty( $settings['translate_content'] ) ) {
|
||||
$translated_content = $this->translator->translate( $post->post_content, $locale );
|
||||
if ( is_wp_error( $translated_content ) ) {
|
||||
WP_CLI::warning( sprintf( '#%d content: %s', $post->ID, $translated_content->get_error_message() ) );
|
||||
++$failures;
|
||||
continue;
|
||||
}
|
||||
$update['post_content'] = $translated_content;
|
||||
}
|
||||
|
||||
$result = wp_update_post( $update, true );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
WP_CLI::warning( sprintf( '#%d save: %s', $post->ID, $result->get_error_message() ) );
|
||||
++$failures;
|
||||
continue;
|
||||
}
|
||||
|
||||
WP_CLI::log( sprintf( 'Updated post #%d.', $post->ID ) );
|
||||
++$successes;
|
||||
}
|
||||
|
||||
WP_CLI::success(
|
||||
sprintf(
|
||||
/* translators: 1: success count, 2: failure count, 3: locale. */
|
||||
__( '%1$d translated, %2$d failed (locale: %3$s).', 'robotstxt-ai-translator' ),
|
||||
$successes,
|
||||
$failures,
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
549
includes/class-ai-translator-editor-ui.php
Normal file
549
includes/class-ai-translator-editor-ui.php
Normal file
|
|
@ -0,0 +1,549 @@
|
|||
<?php
|
||||
/**
|
||||
* Editor UI for the AI Translator plugin.
|
||||
*
|
||||
* Registers the REST endpoint, the Classic editor metabox, and the Block editor
|
||||
* sidebar that lets editors translate the current post.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'AI_Translator_Editor_UI' ) ) {
|
||||
|
||||
/**
|
||||
* Editor UI registration and REST endpoint handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class AI_Translator_Editor_UI {
|
||||
|
||||
/**
|
||||
* Allowed field names that can be translated through the REST endpoint.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var array<int,string>
|
||||
*/
|
||||
const ALLOWED_FIELDS = array( 'title', 'content' );
|
||||
|
||||
/**
|
||||
* Settings handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var AI_Translator_Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Translator handler.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var AI_Translator_Translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param AI_Translator_Settings $settings Settings handler.
|
||||
* @param AI_Translator_Translator $translator Translator handler.
|
||||
*/
|
||||
public function __construct( AI_Translator_Settings $settings, AI_Translator_Translator $translator ) {
|
||||
$this->settings = $settings;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers WordPress hooks.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );
|
||||
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_classic_editor_assets' ) );
|
||||
add_action( 'add_meta_boxes', array( $this, 'register_classic_meta_box' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the REST API routes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_rest_routes() {
|
||||
register_rest_route(
|
||||
AI_TRANSLATOR_REST_NAMESPACE,
|
||||
'/translate',
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'handle_translate_request' ),
|
||||
'permission_callback' => array( $this, 'check_translate_permissions' ),
|
||||
'args' => array(
|
||||
'post_id' => array(
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'minimum' => 1,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'fields' => array(
|
||||
'type' => 'array',
|
||||
'required' => true,
|
||||
'minItems' => 1,
|
||||
'uniqueItems' => true,
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
'enum' => self::ALLOWED_FIELDS,
|
||||
),
|
||||
'sanitize_callback' => 'rest_sanitize_request_arg',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'target_locale' => array(
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'pattern' => '^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$',
|
||||
'maxLength' => 20,
|
||||
'sanitize_callback' => array( $this, 'sanitize_locale' ),
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitises a locale string.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $value Raw value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sanitize_locale( $value ) {
|
||||
$value = is_string( $value ) ? $value : '';
|
||||
$value = preg_replace( '/[^A-Za-z0-9_\-]/', '', $value );
|
||||
|
||||
if ( ! is_string( $value ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return substr( $value, 0, 20 );
|
||||
}
|
||||
|
||||
/**
|
||||
* REST permission callback for the translate endpoint.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return bool|WP_Error True if allowed, WP_Error otherwise.
|
||||
*/
|
||||
public function check_translate_permissions( WP_REST_Request $request ) {
|
||||
$post_id_param = $request->get_param( 'post_id' );
|
||||
$post_id = is_numeric( $post_id_param ) ? (int) $post_id_param : 0;
|
||||
|
||||
if ( $post_id <= 0 || ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__( 'Sorry, you are not allowed to edit this post.', 'robotstxt-ai-translator' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* REST callback for the translate endpoint.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function handle_translate_request( WP_REST_Request $request ) {
|
||||
$post_id_param = $request->get_param( 'post_id' );
|
||||
$target_locale_param = $request->get_param( 'target_locale' );
|
||||
|
||||
$post_id = is_numeric( $post_id_param ) ? (int) $post_id_param : 0;
|
||||
$fields = (array) $request->get_param( 'fields' );
|
||||
$target_locale = is_string( $target_locale_param ) ? $target_locale_param : '';
|
||||
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( ! $post instanceof WP_Post ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_post_not_found',
|
||||
__( 'Post not found.', 'robotstxt-ai-translator' ),
|
||||
array( 'status' => 404 )
|
||||
);
|
||||
}
|
||||
|
||||
$installed = $this->translator->get_installed_locales();
|
||||
if ( ! in_array( $target_locale, $installed, true ) ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_invalid_locale',
|
||||
__( 'The selected language is not installed on this site.', 'robotstxt-ai-translator' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
|
||||
$site_settings = $this->settings->get_settings();
|
||||
$allowed = array();
|
||||
|
||||
if ( in_array( 'title', $fields, true ) && ! empty( $site_settings['translate_title'] ) ) {
|
||||
$allowed[] = 'title';
|
||||
}
|
||||
if ( in_array( 'content', $fields, true ) && ! empty( $site_settings['translate_content'] ) ) {
|
||||
$allowed[] = 'content';
|
||||
}
|
||||
|
||||
if ( empty( $allowed ) ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_no_fields',
|
||||
__( 'No translatable fields were selected, or the requested fields are disabled in the settings.', 'robotstxt-ai-translator' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
|
||||
$response = array();
|
||||
|
||||
if ( in_array( 'title', $allowed, true ) ) {
|
||||
$translated = $this->translator->translate( $post->post_title, $target_locale );
|
||||
if ( is_wp_error( $translated ) ) {
|
||||
return $this->error_with_status( $translated, 502 );
|
||||
}
|
||||
$response['title'] = $translated;
|
||||
}
|
||||
|
||||
if ( in_array( 'content', $allowed, true ) ) {
|
||||
$translated = $this->translator->translate( $post->post_content, $target_locale );
|
||||
if ( is_wp_error( $translated ) ) {
|
||||
return $this->error_with_status( $translated, 502 );
|
||||
}
|
||||
$response['content'] = $translated;
|
||||
}
|
||||
|
||||
return new WP_REST_Response( $response, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an HTTP status to a WP_Error without overwriting existing data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param WP_Error $error The original error.
|
||||
* @param int $status HTTP status code to add.
|
||||
*
|
||||
* @return WP_Error
|
||||
*/
|
||||
private function error_with_status( WP_Error $error, $status ) {
|
||||
$existing = (array) $error->get_error_data();
|
||||
$error->add_data( array_merge( $existing, array( 'status' => (int) $status ) ) );
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the Classic editor metabox.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_classic_meta_box() {
|
||||
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
|
||||
|
||||
// The block editor already shows the AI Translator via the PluginSidebar
|
||||
// (translation icon in the top-right). Skipping metabox registration there
|
||||
// avoids duplicating the UI in the post settings panel.
|
||||
if ( $screen && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_types = $this->get_supported_post_types();
|
||||
|
||||
foreach ( $post_types as $post_type ) {
|
||||
add_meta_box(
|
||||
'ai-translator',
|
||||
__( 'AI Translator', 'robotstxt-ai-translator' ),
|
||||
array( $this, 'render_classic_meta_box' ),
|
||||
$post_type,
|
||||
'side',
|
||||
'default'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Classic editor metabox content.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param WP_Post $post The current post.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_classic_meta_box( $post ) {
|
||||
$languages = $this->get_language_list();
|
||||
$settings = $this->settings->get_settings();
|
||||
|
||||
?>
|
||||
<div id="ai-translator-classic" class="ai-translator-classic" data-post-id="<?php echo esc_attr( (string) $post->ID ); ?>">
|
||||
<?php if ( ! $this->translator->is_available() ) : ?>
|
||||
<p><?php echo esc_html__( 'The WordPress AI plugin is not active. Translation is unavailable.', 'robotstxt-ai-translator' ); ?></p>
|
||||
<?php elseif ( empty( $settings['translate_title'] ) && empty( $settings['translate_content'] ) ) : ?>
|
||||
<p><?php echo esc_html__( 'No translation fields are enabled in settings.', 'robotstxt-ai-translator' ); ?></p>
|
||||
<?php elseif ( empty( $languages ) ) : ?>
|
||||
<p><?php echo esc_html__( 'No languages are installed on this site.', 'robotstxt-ai-translator' ); ?></p>
|
||||
<?php else : ?>
|
||||
<p>
|
||||
<label for="ai-translator-locale"><?php echo esc_html__( 'Target language', 'robotstxt-ai-translator' ); ?></label>
|
||||
<select id="ai-translator-locale" class="widefat">
|
||||
<?php foreach ( $languages as $language ) : ?>
|
||||
<option value="<?php echo esc_attr( $language['locale'] ); ?>"><?php echo esc_html( $language['name'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<button type="button" class="button button-primary" id="ai-translator-classic-button">
|
||||
<?php echo esc_html__( 'Translate', 'robotstxt-ai-translator' ); ?>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_html__( 'Save the post before translating to ensure the latest content is used. The translation replaces the current title and/or content.', 'robotstxt-ai-translator' ); ?>
|
||||
</p>
|
||||
|
||||
<div id="ai-translator-classic-status" class="ai-translator-status" role="status" aria-live="polite"></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues assets for the Classic editor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $hook Current admin page hook.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_classic_editor_assets( $hook ) {
|
||||
if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ), true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
|
||||
|
||||
if ( $screen && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->enqueue_assets( 'classic' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues assets for the Block editor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_block_editor_assets() {
|
||||
$this->enqueue_assets( 'block' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Common asset enqueue logic for both editors.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $context Either 'classic' or 'block'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function enqueue_assets( $context ) {
|
||||
$dependencies = array( 'wp-api-fetch', 'wp-i18n' );
|
||||
|
||||
if ( 'block' === $context ) {
|
||||
$dependencies = array_merge(
|
||||
$dependencies,
|
||||
array(
|
||||
'wp-plugins',
|
||||
'wp-editor',
|
||||
'wp-element',
|
||||
'wp-components',
|
||||
'wp-data',
|
||||
'wp-blocks',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$asset_ver = AI_TRANSLATOR_VERSION . '.' . (string) filemtime( AI_TRANSLATOR_DIR . 'assets/js/editor.js' );
|
||||
|
||||
wp_register_script(
|
||||
'ai-translator-editor',
|
||||
AI_TRANSLATOR_URL . 'assets/js/editor.js',
|
||||
$dependencies,
|
||||
$asset_ver,
|
||||
true
|
||||
);
|
||||
|
||||
wp_register_style(
|
||||
'ai-translator-editor',
|
||||
AI_TRANSLATOR_URL . 'assets/css/editor.css',
|
||||
array(),
|
||||
$asset_ver
|
||||
);
|
||||
|
||||
$post_id = $this->resolve_current_post_id();
|
||||
$settings = $this->settings->get_settings();
|
||||
|
||||
$data = array(
|
||||
'restNamespace' => AI_TRANSLATOR_REST_NAMESPACE,
|
||||
'restRoute' => '/translate',
|
||||
'context' => $context,
|
||||
'postId' => $post_id,
|
||||
'available' => $this->translator->is_available(),
|
||||
'languages' => $this->get_language_list(),
|
||||
'settings' => array(
|
||||
'translateTitle' => ! empty( $settings['translate_title'] ),
|
||||
'translateContent' => ! empty( $settings['translate_content'] ),
|
||||
),
|
||||
'i18n' => array(
|
||||
'translate' => __( 'Translate', 'robotstxt-ai-translator' ),
|
||||
'translating' => __( 'Translating…', 'robotstxt-ai-translator' ),
|
||||
'targetLanguage' => __( 'Target language', 'robotstxt-ai-translator' ),
|
||||
'panelTitle' => __( 'AI Translator', 'robotstxt-ai-translator' ),
|
||||
'success' => __( 'Translation applied. Review and save the post.', 'robotstxt-ai-translator' ),
|
||||
'genericError' => __( 'Translation failed.', 'robotstxt-ai-translator' ),
|
||||
'noLanguages' => __( 'No languages are installed on this site.', 'robotstxt-ai-translator' ),
|
||||
'noFields' => __( 'No translation fields are enabled in settings.', 'robotstxt-ai-translator' ),
|
||||
'aiUnavailable' => __( 'The WordPress AI plugin is not active.', 'robotstxt-ai-translator' ),
|
||||
'saveBeforeWarn' => __( 'You have unsaved changes. Save the post before translating to ensure the latest content is used.', 'robotstxt-ai-translator' ),
|
||||
'translateTitle' => __( 'Translate title', 'robotstxt-ai-translator' ),
|
||||
'translateContent' => __( 'Translate content', 'robotstxt-ai-translator' ),
|
||||
),
|
||||
);
|
||||
|
||||
wp_add_inline_script(
|
||||
'ai-translator-editor',
|
||||
'window.aiTranslatorData = ' . wp_json_encode( $data ) . ';',
|
||||
'before'
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'ai-translator-editor' );
|
||||
wp_enqueue_style( 'ai-translator-editor' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the current post ID when enqueueing assets.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return int Post ID, or 0 when it cannot be determined.
|
||||
*/
|
||||
private function resolve_current_post_id() {
|
||||
$post = get_post();
|
||||
|
||||
if ( $post instanceof WP_Post ) {
|
||||
return (int) $post->ID;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$post_get = wp_unslash( $_GET['post'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
return is_scalar( $post_get ) ? absint( $post_get ) : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the post types where the metabox should appear.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
private function get_supported_post_types() {
|
||||
$post_types = get_post_types( array( 'public' => true ), 'names' );
|
||||
|
||||
if ( ! is_array( $post_types ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
unset( $post_types['attachment'] );
|
||||
|
||||
/**
|
||||
* Filters the post types where the AI Translator metabox is registered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<int,string> $post_types List of post type names.
|
||||
*/
|
||||
return (array) apply_filters( 'ai_translator_supported_post_types', array_values( $post_types ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of languages available for translation on this site.
|
||||
*
|
||||
* Includes en_US plus any locales whose .mo files are installed.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array<int,array{locale:string,name:string}>
|
||||
*/
|
||||
private function get_language_list() {
|
||||
$locales = $this->translator->get_installed_locales();
|
||||
|
||||
if ( ! function_exists( 'wp_get_available_translations' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
||||
}
|
||||
|
||||
$translations = function_exists( 'wp_get_available_translations' ) ? wp_get_available_translations() : array();
|
||||
$languages = array();
|
||||
|
||||
foreach ( $locales as $locale ) {
|
||||
if ( 'en_US' === $locale ) {
|
||||
$name = 'English (United States)';
|
||||
} elseif ( isset( $translations[ $locale ]['native_name'] ) && '' !== $translations[ $locale ]['native_name'] ) {
|
||||
$name = (string) $translations[ $locale ]['native_name'];
|
||||
} elseif ( isset( $translations[ $locale ]['english_name'] ) && '' !== $translations[ $locale ]['english_name'] ) {
|
||||
$name = (string) $translations[ $locale ]['english_name'];
|
||||
} else {
|
||||
$name = $locale;
|
||||
}
|
||||
|
||||
$languages[] = array(
|
||||
'locale' => $locale,
|
||||
'name' => $name,
|
||||
);
|
||||
}
|
||||
|
||||
usort(
|
||||
$languages,
|
||||
static function ( $a, $b ) {
|
||||
return strcasecmp( $a['name'], $b['name'] );
|
||||
}
|
||||
);
|
||||
|
||||
return $languages;
|
||||
}
|
||||
}
|
||||
}
|
||||
210
includes/class-ai-translator-settings.php
Normal file
210
includes/class-ai-translator-settings.php
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
<?php
|
||||
/**
|
||||
* Settings management for the AI Translator plugin.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'AI_Translator_Settings' ) ) {
|
||||
|
||||
/**
|
||||
* Handles reading and writing the plugin settings in single-site and Multisite contexts.
|
||||
*
|
||||
* In Multisite, the network admin chooses between two modes:
|
||||
* - "global" : a single configuration shared by every subsite.
|
||||
* - "per-site" : each subsite stores its own configuration, with the network values
|
||||
* acting as defaults when a subsite has not been configured yet.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class AI_Translator_Settings {
|
||||
|
||||
/**
|
||||
* Option key for site-level settings (single-site or per-site Multisite mode).
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const OPTION_SITE = 'ai_translator_settings';
|
||||
|
||||
/**
|
||||
* Sitemeta key for network-level settings (Multisite global mode and defaults).
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const OPTION_NETWORK = 'ai_translator_settings';
|
||||
|
||||
/**
|
||||
* Sitemeta key for the configuration mode in Multisite.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
const OPTION_MODE = 'ai_translator_network_mode';
|
||||
|
||||
/**
|
||||
* Default settings values.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var array<string,bool>
|
||||
*/
|
||||
const DEFAULTS = array(
|
||||
'translate_title' => true,
|
||||
'translate_content' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the current configuration mode in Multisite.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string Either 'global' or 'per-site'. Returns 'global' on single-site installs.
|
||||
*/
|
||||
public function get_network_mode() {
|
||||
if ( ! is_multisite() ) {
|
||||
return 'global';
|
||||
}
|
||||
|
||||
$mode = get_site_option( self::OPTION_MODE, 'global' );
|
||||
|
||||
return in_array( $mode, array( 'global', 'per-site' ), true ) ? $mode : 'global';
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Multisite configuration mode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $mode Either 'global' or 'per-site'.
|
||||
*
|
||||
* @return bool True on success.
|
||||
*/
|
||||
public function update_network_mode( $mode ) {
|
||||
if ( ! is_multisite() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mode = in_array( $mode, array( 'global', 'per-site' ), true ) ? $mode : 'global';
|
||||
|
||||
return (bool) update_site_option( self::OPTION_MODE, $mode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective settings for a given site, applying multisite mode rules.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int|null $blog_id Optional blog ID. Defaults to the current site.
|
||||
*
|
||||
* @return array<string,bool> Settings array with boolean values.
|
||||
*/
|
||||
public function get_settings( $blog_id = null ) {
|
||||
if ( ! is_multisite() ) {
|
||||
return $this->normalize( (array) get_option( self::OPTION_SITE, array() ) );
|
||||
}
|
||||
|
||||
$mode = $this->get_network_mode();
|
||||
|
||||
if ( 'global' === $mode ) {
|
||||
return $this->normalize( (array) get_site_option( self::OPTION_NETWORK, array() ) );
|
||||
}
|
||||
|
||||
$network_defaults = $this->normalize( (array) get_site_option( self::OPTION_NETWORK, array() ) );
|
||||
|
||||
if ( null === $blog_id || get_current_blog_id() === (int) $blog_id ) {
|
||||
$site_settings = get_option( self::OPTION_SITE, null );
|
||||
} else {
|
||||
switch_to_blog( (int) $blog_id );
|
||||
$site_settings = get_option( self::OPTION_SITE, null );
|
||||
restore_current_blog();
|
||||
}
|
||||
|
||||
if ( null === $site_settings ) {
|
||||
return $network_defaults;
|
||||
}
|
||||
|
||||
return $this->normalize( array_merge( $network_defaults, (array) $site_settings ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw network-level settings (used by the network admin form).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array<string,bool>
|
||||
*/
|
||||
public function get_network_settings() {
|
||||
return $this->normalize( (array) get_site_option( self::OPTION_NETWORK, array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw site-level settings (used by the site admin form).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array<string,bool>
|
||||
*/
|
||||
public function get_site_settings() {
|
||||
return $this->normalize( (array) get_option( self::OPTION_SITE, array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the network-level settings (Multisite only).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<string,bool> $settings Settings to store.
|
||||
*
|
||||
* @return bool True on success.
|
||||
*/
|
||||
public function update_network_settings( array $settings ) {
|
||||
if ( ! is_multisite() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) update_site_option( self::OPTION_NETWORK, $this->normalize( $settings ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the site-level settings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<string,bool> $settings Settings to store.
|
||||
*
|
||||
* @return bool True on success.
|
||||
*/
|
||||
public function update_site_settings( array $settings ) {
|
||||
return (bool) update_option( self::OPTION_SITE, $this->normalize( $settings ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalises raw settings into a strict array of booleans matching the schema.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array<int|string,mixed> $settings Raw settings.
|
||||
*
|
||||
* @return array<string,bool>
|
||||
*/
|
||||
private function normalize( array $settings ) {
|
||||
$normalized = array();
|
||||
|
||||
foreach ( self::DEFAULTS as $key => $default ) {
|
||||
if ( array_key_exists( $key, $settings ) ) {
|
||||
$normalized[ $key ] = (bool) $settings[ $key ];
|
||||
} else {
|
||||
$normalized[ $key ] = (bool) $default;
|
||||
}
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
}
|
||||
}
|
||||
201
includes/class-ai-translator-translator.php
Normal file
201
includes/class-ai-translator-translator.php
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
/**
|
||||
* Translation engine for the AI Translator plugin.
|
||||
*
|
||||
* Wraps the WordPress AI client (https://github.com/WordPress/ai) so the rest of the
|
||||
* plugin does not need to know which AI provider is configured.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'AI_Translator_Translator' ) ) {
|
||||
|
||||
/**
|
||||
* Talks to the WordPress AI client to translate strings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class AI_Translator_Translator {
|
||||
|
||||
/**
|
||||
* Indicates whether the WordPress AI client is available.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool True if the dependency is active.
|
||||
*/
|
||||
public function is_available() {
|
||||
return function_exists( 'wp_ai_client_prompt' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the WordPress AI client supports text generation right now.
|
||||
*
|
||||
* The check uses a tiny dummy prompt so the AI client can answer whether at
|
||||
* least one configured provider can serve text generation requests.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool True if text generation is supported.
|
||||
*/
|
||||
public function is_supported() {
|
||||
if ( ! $this->is_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$builder = wp_ai_client_prompt( 'test' );
|
||||
|
||||
return (bool) $builder->is_supported_for_text_generation();
|
||||
} catch ( Exception $e ) {
|
||||
return false;
|
||||
} catch ( Throwable $e ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a single piece of text to the target locale.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $text Source text. Plain text or HTML; preserved as-is.
|
||||
* @param string $target_locale WordPress locale code (for example: es_ES, en_US, fr_FR).
|
||||
*
|
||||
* @return string|WP_Error Translated text, or WP_Error on failure.
|
||||
*/
|
||||
public function translate( $text, $target_locale ) {
|
||||
$text = (string) $text;
|
||||
|
||||
if ( '' === trim( $text ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! $this->is_available() ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_unavailable',
|
||||
__( 'The WordPress AI client is not available. Install and activate the WordPress AI plugin.', 'robotstxt-ai-translator' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $this->is_supported() ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_unsupported',
|
||||
__( 'The configured AI providers cannot serve text generation requests. Open the WordPress AI settings to configure a provider.', 'robotstxt-ai-translator' )
|
||||
);
|
||||
}
|
||||
|
||||
$language_name = $this->locale_to_language_name( $target_locale );
|
||||
|
||||
if ( '' === $language_name ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_invalid_locale',
|
||||
__( 'The target language is not installed on this site.', 'robotstxt-ai-translator' )
|
||||
);
|
||||
}
|
||||
|
||||
$system_instruction = sprintf(
|
||||
/* translators: %s: target language name. */
|
||||
__( 'You are a professional translator. Translate the user message into %s. Preserve any HTML, shortcodes, line breaks, and Markdown exactly as they appear. Return only the translated text, without explanations, prefaces, or quotation marks.', 'robotstxt-ai-translator' ),
|
||||
$language_name
|
||||
);
|
||||
|
||||
try {
|
||||
$result = wp_ai_client_prompt( $text )
|
||||
->using_system_instruction( $system_instruction )
|
||||
->generate_text();
|
||||
} catch ( Exception $e ) {
|
||||
return new WP_Error( 'ai_translator_exception', $e->getMessage() );
|
||||
} catch ( Throwable $e ) {
|
||||
return new WP_Error( 'ai_translator_exception', $e->getMessage() );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( ! is_string( $result ) ) {
|
||||
return new WP_Error(
|
||||
'ai_translator_invalid_response',
|
||||
__( 'The AI service returned an unexpected response.', 'robotstxt-ai-translator' )
|
||||
);
|
||||
}
|
||||
|
||||
return trim( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a WordPress locale code into a human-readable language name.
|
||||
*
|
||||
* Only locales installed on the site (en_US plus any installed .po files) are
|
||||
* accepted, so the editor cannot request translations to languages that the
|
||||
* site has not declared as available.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $locale WordPress locale code.
|
||||
*
|
||||
* @return string Native language name, or empty string when the locale is not installed.
|
||||
*/
|
||||
public function locale_to_language_name( $locale ) {
|
||||
$locale = (string) $locale;
|
||||
|
||||
if ( '' === $locale ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$installed = $this->get_installed_locales();
|
||||
|
||||
if ( ! in_array( $locale, $installed, true ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( 'en_US' === $locale ) {
|
||||
return 'English (United States)';
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_get_available_translations' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
||||
}
|
||||
|
||||
if ( function_exists( 'wp_get_available_translations' ) ) {
|
||||
$translations = wp_get_available_translations();
|
||||
if ( isset( $translations[ $locale ]['native_name'] ) && '' !== $translations[ $locale ]['native_name'] ) {
|
||||
return (string) $translations[ $locale ]['native_name'];
|
||||
}
|
||||
if ( isset( $translations[ $locale ]['english_name'] ) && '' !== $translations[ $locale ]['english_name'] ) {
|
||||
return (string) $translations[ $locale ]['english_name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locales installed on the site, including en_US.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array<int,string> List of locale codes.
|
||||
*/
|
||||
public function get_installed_locales() {
|
||||
$locales = array( 'en_US' );
|
||||
|
||||
if ( function_exists( 'get_available_languages' ) ) {
|
||||
$installed = get_available_languages();
|
||||
if ( is_array( $installed ) ) {
|
||||
foreach ( $installed as $locale ) {
|
||||
$locales[] = (string) $locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values( array_unique( $locales ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
2
languages/robotstxt-ai-translator-ca.l10n.php
Normal file
2
languages/robotstxt-ai-translator-ca.l10n.php
Normal file
File diff suppressed because one or more lines are too long
BIN
languages/robotstxt-ai-translator-ca.mo
Normal file
BIN
languages/robotstxt-ai-translator-ca.mo
Normal file
Binary file not shown.
279
languages/robotstxt-ai-translator-ca.po
Normal file
279
languages/robotstxt-ai-translator-ca.po
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
# Copyright (C) 2026 ROBOTSTXT
|
||||
# This file is distributed under the GPL-3.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: AI Translator (by ROBOTSTXT) 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator\n"
|
||||
"Last-Translator: ROBOTSTXT <hello@robotstxt.es>\n"
|
||||
"Language-Team: Catalan\n"
|
||||
"Language: ca\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-05-23T10:07:42+00:00\n"
|
||||
"PO-Revision-Date: 2026-05-23 10:30+0000\n"
|
||||
"X-Generator: hand-written\n"
|
||||
"X-Domain: robotstxt-ai-translator\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. Plugin Name of the plugin
|
||||
msgid "AI Translator (by ROBOTSTXT)"
|
||||
msgstr "AI Translator (by ROBOTSTXT)"
|
||||
|
||||
#. Description of the plugin
|
||||
msgid "Translate post titles and content from the editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration."
|
||||
msgstr "Tradueix el títol i el contingut de les entrades des de l'editor utilitzant el connector natiu d'IA de WordPress com a backend. Compatible amb Multisite en mode global o per lloc."
|
||||
|
||||
#. Author of the plugin
|
||||
msgid "ROBOTSTXT"
|
||||
msgstr "ROBOTSTXT"
|
||||
|
||||
msgid "AI Translator"
|
||||
msgstr "AI Translator"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "Ajustaments"
|
||||
|
||||
msgid "You do not have permission to access this page."
|
||||
msgstr "No tens permís per accedir a aquesta pàgina."
|
||||
|
||||
msgid "AI Translator Settings"
|
||||
msgstr "Ajustaments d'AI Translator"
|
||||
|
||||
msgid "Settings saved."
|
||||
msgstr "Ajustaments desats."
|
||||
|
||||
msgid "Translation fields"
|
||||
msgstr "Camps a traduir"
|
||||
|
||||
msgid "Translate title"
|
||||
msgstr "Tradueix el títol"
|
||||
|
||||
msgid "Translate content"
|
||||
msgstr "Tradueix el contingut"
|
||||
|
||||
#. translators: 1: title default, 2: content default.
|
||||
#, php-format
|
||||
msgid "Network defaults: title %1$s, content %2$s."
|
||||
msgstr "Valors predeterminats de la xarxa: títol %1$s, contingut %2$s."
|
||||
|
||||
msgid "enabled"
|
||||
msgstr "activat"
|
||||
|
||||
msgid "disabled"
|
||||
msgstr "desactivat"
|
||||
|
||||
msgid "AI Translator Network Settings"
|
||||
msgstr "Ajustaments de xarxa d'AI Translator"
|
||||
|
||||
msgid "Network settings saved."
|
||||
msgstr "Ajustaments de xarxa desats."
|
||||
|
||||
msgid "Configuration mode"
|
||||
msgstr "Mode de configuració"
|
||||
|
||||
msgid "Global configuration: a single setting applies to every site."
|
||||
msgstr "Configuració global: un sol ajustament s'aplica a tots els llocs."
|
||||
|
||||
msgid "Per-site configuration: each site can override these defaults."
|
||||
msgstr "Configuració per lloc: cada lloc pot sobreescriure aquests valors predeterminats."
|
||||
|
||||
msgid "In global mode this is the configuration for the whole network. In per-site mode these values are used as defaults for sites that have not been configured individually."
|
||||
msgstr "En mode global aquesta és la configuració per a tota la xarxa. En mode per lloc aquests valors s'utilitzen com a predeterminats per als llocs que no s'hagin configurat individualment."
|
||||
|
||||
msgid "You do not have permission to perform this action."
|
||||
msgstr "No tens permís per dur a terme aquesta acció."
|
||||
|
||||
msgid "Recommended models"
|
||||
msgstr "Models recomanats"
|
||||
|
||||
msgid "This plugin does not call AI providers directly. Configure your preferred provider in the WordPress AI plugin settings. The table below is a guide to help you pick a model based on your translation use case."
|
||||
msgstr "Aquest connector no truca directament als proveïdors d'IA. Configura el teu proveïdor preferit als ajustaments del connector WordPress AI. La taula següent és una guia per ajudar-te a triar un model segons el teu cas d'ús de traducció."
|
||||
|
||||
msgid "Use case"
|
||||
msgstr "Cas d'ús"
|
||||
|
||||
msgid "Recommended model"
|
||||
msgstr "Model recomanat"
|
||||
|
||||
msgid "Why"
|
||||
msgstr "Per què"
|
||||
|
||||
msgid "These recommendations are based on public benchmarks and community feedback as of the plugin release date. They may change as providers update their models."
|
||||
msgstr "Aquestes recomanacions es basen en benchmarks públics i comentaris de la comunitat en la data de publicació del connector. Poden canviar a mesura que els proveïdors actualitzin els seus models."
|
||||
|
||||
msgid "European languages (ES, CA, FR, DE, IT, PT)"
|
||||
msgstr "Llengües europees (ES, CA, FR, DE, IT, PT)"
|
||||
|
||||
msgid "DeepL API Pro"
|
||||
msgstr "DeepL API Pro"
|
||||
|
||||
msgid "Best fluency and naturalness (92/100 in benchmarks). Formality control and custom glossaries."
|
||||
msgstr "La millor fluïdesa i naturalitat (92/100 en benchmarks). Control de formalitat i glossaris personalitzats."
|
||||
|
||||
msgid "Asian languages (ZH, JA, KO)"
|
||||
msgstr "Llengües asiàtiques (ZH, JA, KO)"
|
||||
|
||||
msgid "GPT-4o / GPT-5 or Claude Sonnet 4"
|
||||
msgstr "GPT-4o / GPT-5 o Claude Sonnet 4"
|
||||
|
||||
msgid "Better handling of implicit subjects, honorifics, and cultural references. DeepL falls behind here."
|
||||
msgstr "Millor gestió dels subjectes implícits, els honorífics i les referències culturals. DeepL queda enrere aquí."
|
||||
|
||||
msgid "Marketing / brand tone"
|
||||
msgstr "Màrqueting / to de marca"
|
||||
|
||||
msgid "Claude Sonnet 4 / Opus 4"
|
||||
msgstr "Claude Sonnet 4 / Opus 4"
|
||||
|
||||
msgid "Better preservation of tone, brand voice, and nuance. Ideal for creative copy."
|
||||
msgstr "Preserva millor el to, la veu de la marca i els matisos. Ideal per a copy creatiu."
|
||||
|
||||
msgid "Technical documentation / code"
|
||||
msgstr "Documentació tècnica / codi"
|
||||
|
||||
msgid "GPT-4o / GPT-5"
|
||||
msgstr "GPT-4o / GPT-5"
|
||||
|
||||
msgid "Higher accuracy with variables, structured formats, and technical terminology."
|
||||
msgstr "Major precisió amb variables, formats estructurats i terminologia tècnica."
|
||||
|
||||
msgid "Long documents (100+ pages)"
|
||||
msgstr "Documents llargs (més de 100 pàgines)"
|
||||
|
||||
msgid "Gemini 2.5 Pro"
|
||||
msgstr "Gemini 2.5 Pro"
|
||||
|
||||
msgid "1M token context window. Maintains terminological consistency across long texts."
|
||||
msgstr "Finestra de context d'1 milió de tokens. Manté la consistència terminològica en textos llargs."
|
||||
|
||||
msgid "High volume / low cost"
|
||||
msgstr "Alt volum / baix cost"
|
||||
|
||||
msgid "DeepSeek-V3"
|
||||
msgstr "DeepSeek-V3"
|
||||
|
||||
msgid "Quality comparable to GPT-5 at ~$0.14/M tokens (20-50x cheaper than Claude/GPT)."
|
||||
msgstr "Qualitat comparable a GPT-5 a ~0,14 $/M tokens (entre 20 i 50 vegades més barat que Claude/GPT)."
|
||||
|
||||
msgid "Rare / indigenous languages"
|
||||
msgstr "Llengües rares / indígenes"
|
||||
|
||||
msgid "Claude Sonnet or Taskade Translate (multi-model routing)"
|
||||
msgstr "Claude Sonnet o Taskade Translate (encaminament multimodel)"
|
||||
|
||||
msgid "Better coverage for uncommon language pairs."
|
||||
msgstr "Millor cobertura en parells de llengües poc habituals."
|
||||
|
||||
msgid "Maximum coverage (133+ languages)"
|
||||
msgstr "Cobertura màxima (més de 133 llengües)"
|
||||
|
||||
msgid "Google Cloud Translation"
|
||||
msgstr "Google Cloud Translation"
|
||||
|
||||
msgid "The most complete option, though with slightly lower quality on European languages."
|
||||
msgstr "L'opció més completa, tot i que amb una qualitat lleugerament inferior en llengües europees."
|
||||
|
||||
msgid "The --locale flag is required."
|
||||
msgstr "El paràmetre --locale és obligatori."
|
||||
|
||||
msgid "The --post-id and --post-type flags are mutually exclusive."
|
||||
msgstr "Els paràmetres --post-id i --post-type són mútuament excloents."
|
||||
|
||||
msgid "No user context. Pass --user=<id|login> so post updates carry an author and capability checks apply."
|
||||
msgstr "Sense context d'usuari. Passa --user=<id|login> perquè les actualitzacions d'entrades tinguin autor i s'apliquin les comprovacions de capacitats."
|
||||
|
||||
msgid "The WordPress AI plugin is not active."
|
||||
msgstr "El connector WordPress AI no està actiu."
|
||||
|
||||
msgid "The WordPress AI plugin has no provider configured for text generation."
|
||||
msgstr "El connector WordPress AI no té cap proveïdor configurat per a la generació de text."
|
||||
|
||||
#. translators: %s: locale code.
|
||||
#, php-format
|
||||
msgid "The locale %s is not installed on this site."
|
||||
msgstr "La llengua %s no està instal·lada en aquest lloc."
|
||||
|
||||
msgid "No translation fields are enabled in the plugin settings."
|
||||
msgstr "No hi ha cap camp de traducció activat als ajustaments del connector."
|
||||
|
||||
msgid "No posts matched the given criteria."
|
||||
msgstr "Cap entrada coincideix amb els criteris donats."
|
||||
|
||||
#. translators: 1: success count, 2: failure count, 3: locale.
|
||||
#, php-format
|
||||
msgid "%1$d translated, %2$d failed (locale: %3$s)."
|
||||
msgstr "%1$d traduïdes, %2$d amb errors (llengua: %3$s)."
|
||||
|
||||
msgid "Sorry, you are not allowed to edit this post."
|
||||
msgstr "Ho sentim, no tens permís per editar aquesta entrada."
|
||||
|
||||
msgid "Post not found."
|
||||
msgstr "Entrada no trobada."
|
||||
|
||||
msgid "The selected language is not installed on this site."
|
||||
msgstr "La llengua seleccionada no està instal·lada en aquest lloc."
|
||||
|
||||
msgid "No translatable fields were selected, or the requested fields are disabled in the settings."
|
||||
msgstr "No s'ha seleccionat cap camp traduïble, o els camps sol·licitats estan desactivats als ajustaments."
|
||||
|
||||
msgid "The WordPress AI plugin is not active. Translation is unavailable."
|
||||
msgstr "El connector WordPress AI no està actiu. La traducció no està disponible."
|
||||
|
||||
msgid "No translation fields are enabled in settings."
|
||||
msgstr "No hi ha cap camp de traducció activat als ajustaments."
|
||||
|
||||
msgid "No languages are installed on this site."
|
||||
msgstr "No hi ha cap llengua instal·lada en aquest lloc."
|
||||
|
||||
msgid "Target language"
|
||||
msgstr "Llengua de destinació"
|
||||
|
||||
msgid "Translate"
|
||||
msgstr "Tradueix"
|
||||
|
||||
msgid "Save the post before translating to ensure the latest content is used. The translation replaces the current title and/or content."
|
||||
msgstr "Desa l'entrada abans de traduir perquè s'utilitzi la versió més recent. La traducció substitueix el títol i/o el contingut actuals."
|
||||
|
||||
msgid "Translating…"
|
||||
msgstr "Traduint…"
|
||||
|
||||
msgid "Translation applied. Review and save the post."
|
||||
msgstr "Traducció aplicada. Revisa i desa l'entrada."
|
||||
|
||||
msgid "Translation failed."
|
||||
msgstr "La traducció ha fallat."
|
||||
|
||||
msgid "You have unsaved changes. Save the post before translating to ensure the latest content is used."
|
||||
msgstr "Tens canvis sense desar. Desa l'entrada abans de traduir perquè s'utilitzi la versió més recent."
|
||||
|
||||
msgid "The WordPress AI client is not available. Install and activate the WordPress AI plugin."
|
||||
msgstr "El client de WordPress AI no està disponible. Instal·la i activa el connector WordPress AI."
|
||||
|
||||
msgid "The configured AI providers cannot serve text generation requests. Open the WordPress AI settings to configure a provider."
|
||||
msgstr "Els proveïdors d'IA configurats no poden atendre peticions de generació de text. Obre els ajustaments de WordPress AI per configurar un proveïdor."
|
||||
|
||||
msgid "The target language is not installed on this site."
|
||||
msgstr "La llengua de destinació no està instal·lada en aquest lloc."
|
||||
|
||||
#. translators: %s: target language name.
|
||||
#, php-format
|
||||
msgid "You are a professional translator. Translate the user message into %s. Preserve any HTML, shortcodes, line breaks, and Markdown exactly as they appear. Return only the translated text, without explanations, prefaces, or quotation marks."
|
||||
msgstr "Ets un traductor professional. Tradueix el missatge de l'usuari al %s. Preserva l'HTML, els shortcodes, els salts de línia i el Markdown exactament com apareixen. Retorna només el text traduït, sense explicacions, prefacis ni cometes."
|
||||
|
||||
msgid "The AI service returned an unexpected response."
|
||||
msgstr "El servei d'IA ha retornat una resposta inesperada."
|
||||
|
||||
#. translators: %s: WordPress AI plugin link.
|
||||
#, php-format
|
||||
msgid "AI Translator (by ROBOTSTXT) requires the %s plugin to be active. Translation features will be disabled until it is installed and configured."
|
||||
msgstr "AI Translator (by ROBOTSTXT) necessita que el connector %s estigui actiu. Les funcions de traducció estaran desactivades fins que s'instal·li i es configuri."
|
||||
|
||||
msgid "WordPress AI"
|
||||
msgstr "WordPress AI"
|
||||
|
||||
msgid "Security check failed"
|
||||
msgstr "Comprovació de seguretat fallida"
|
||||
|
||||
msgid "You do not have sufficient permissions to access this page."
|
||||
msgstr "No tens permisos suficients per accedir a aquesta pàgina."
|
||||
2
languages/robotstxt-ai-translator-es_ES.l10n.php
Normal file
2
languages/robotstxt-ai-translator-es_ES.l10n.php
Normal file
File diff suppressed because one or more lines are too long
BIN
languages/robotstxt-ai-translator-es_ES.mo
Normal file
BIN
languages/robotstxt-ai-translator-es_ES.mo
Normal file
Binary file not shown.
279
languages/robotstxt-ai-translator-es_ES.po
Normal file
279
languages/robotstxt-ai-translator-es_ES.po
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
# Copyright (C) 2026 ROBOTSTXT
|
||||
# This file is distributed under the GPL-3.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: AI Translator (by ROBOTSTXT) 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator\n"
|
||||
"Last-Translator: ROBOTSTXT <hello@robotstxt.es>\n"
|
||||
"Language-Team: Spanish (Spain)\n"
|
||||
"Language: es_ES\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-05-23T10:07:42+00:00\n"
|
||||
"PO-Revision-Date: 2026-05-23 10:30+0000\n"
|
||||
"X-Generator: hand-written\n"
|
||||
"X-Domain: robotstxt-ai-translator\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. Plugin Name of the plugin
|
||||
msgid "AI Translator (by ROBOTSTXT)"
|
||||
msgstr "AI Translator (by ROBOTSTXT)"
|
||||
|
||||
#. Description of the plugin
|
||||
msgid "Translate post titles and content from the editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration."
|
||||
msgstr "Traduce el título y el contenido de las entradas desde el editor usando el plugin nativo de IA de WordPress como backend. Compatible con Multisitio en modo global o por sitio."
|
||||
|
||||
#. Author of the plugin
|
||||
msgid "ROBOTSTXT"
|
||||
msgstr "ROBOTSTXT"
|
||||
|
||||
msgid "AI Translator"
|
||||
msgstr "AI Translator"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "Ajustes"
|
||||
|
||||
msgid "You do not have permission to access this page."
|
||||
msgstr "No tienes permiso para acceder a esta página."
|
||||
|
||||
msgid "AI Translator Settings"
|
||||
msgstr "Ajustes de AI Translator"
|
||||
|
||||
msgid "Settings saved."
|
||||
msgstr "Ajustes guardados."
|
||||
|
||||
msgid "Translation fields"
|
||||
msgstr "Campos a traducir"
|
||||
|
||||
msgid "Translate title"
|
||||
msgstr "Traducir título"
|
||||
|
||||
msgid "Translate content"
|
||||
msgstr "Traducir contenido"
|
||||
|
||||
#. translators: 1: title default, 2: content default.
|
||||
#, php-format
|
||||
msgid "Network defaults: title %1$s, content %2$s."
|
||||
msgstr "Valores por defecto de la red: título %1$s, contenido %2$s."
|
||||
|
||||
msgid "enabled"
|
||||
msgstr "activado"
|
||||
|
||||
msgid "disabled"
|
||||
msgstr "desactivado"
|
||||
|
||||
msgid "AI Translator Network Settings"
|
||||
msgstr "Ajustes de red de AI Translator"
|
||||
|
||||
msgid "Network settings saved."
|
||||
msgstr "Ajustes de red guardados."
|
||||
|
||||
msgid "Configuration mode"
|
||||
msgstr "Modo de configuración"
|
||||
|
||||
msgid "Global configuration: a single setting applies to every site."
|
||||
msgstr "Configuración global: un único ajuste se aplica a todos los sitios."
|
||||
|
||||
msgid "Per-site configuration: each site can override these defaults."
|
||||
msgstr "Configuración por sitio: cada sitio puede sobrescribir estos valores por defecto."
|
||||
|
||||
msgid "In global mode this is the configuration for the whole network. In per-site mode these values are used as defaults for sites that have not been configured individually."
|
||||
msgstr "En modo global esta es la configuración para toda la red. En modo por sitio estos valores se usan como predeterminados para los sitios que no se hayan configurado individualmente."
|
||||
|
||||
msgid "You do not have permission to perform this action."
|
||||
msgstr "No tienes permiso para realizar esta acción."
|
||||
|
||||
msgid "Recommended models"
|
||||
msgstr "Modelos recomendados"
|
||||
|
||||
msgid "This plugin does not call AI providers directly. Configure your preferred provider in the WordPress AI plugin settings. The table below is a guide to help you pick a model based on your translation use case."
|
||||
msgstr "Este plugin no llama directamente a los proveedores de IA. Configura tu proveedor preferido en los ajustes del plugin WordPress AI. La tabla siguiente es una guía para ayudarte a elegir un modelo según tu caso de uso de traducción."
|
||||
|
||||
msgid "Use case"
|
||||
msgstr "Caso de uso"
|
||||
|
||||
msgid "Recommended model"
|
||||
msgstr "Modelo recomendado"
|
||||
|
||||
msgid "Why"
|
||||
msgstr "Por qué"
|
||||
|
||||
msgid "These recommendations are based on public benchmarks and community feedback as of the plugin release date. They may change as providers update their models."
|
||||
msgstr "Estas recomendaciones se basan en benchmarks públicos y comentarios de la comunidad en la fecha de publicación del plugin. Pueden cambiar a medida que los proveedores actualicen sus modelos."
|
||||
|
||||
msgid "European languages (ES, CA, FR, DE, IT, PT)"
|
||||
msgstr "Idiomas europeos (ES, CA, FR, DE, IT, PT)"
|
||||
|
||||
msgid "DeepL API Pro"
|
||||
msgstr "DeepL API Pro"
|
||||
|
||||
msgid "Best fluency and naturalness (92/100 in benchmarks). Formality control and custom glossaries."
|
||||
msgstr "La mejor fluidez y naturalidad (92/100 en benchmarks). Control de formalidad y glosarios personalizados."
|
||||
|
||||
msgid "Asian languages (ZH, JA, KO)"
|
||||
msgstr "Idiomas asiáticos (ZH, JA, KO)"
|
||||
|
||||
msgid "GPT-4o / GPT-5 or Claude Sonnet 4"
|
||||
msgstr "GPT-4o / GPT-5 o Claude Sonnet 4"
|
||||
|
||||
msgid "Better handling of implicit subjects, honorifics, and cultural references. DeepL falls behind here."
|
||||
msgstr "Mejor manejo de sujetos implícitos, honoríficos y referencias culturales. DeepL queda por detrás aquí."
|
||||
|
||||
msgid "Marketing / brand tone"
|
||||
msgstr "Marketing / tono de marca"
|
||||
|
||||
msgid "Claude Sonnet 4 / Opus 4"
|
||||
msgstr "Claude Sonnet 4 / Opus 4"
|
||||
|
||||
msgid "Better preservation of tone, brand voice, and nuance. Ideal for creative copy."
|
||||
msgstr "Preserva mejor el tono, la voz de marca y los matices. Ideal para copy creativo."
|
||||
|
||||
msgid "Technical documentation / code"
|
||||
msgstr "Documentación técnica / código"
|
||||
|
||||
msgid "GPT-4o / GPT-5"
|
||||
msgstr "GPT-4o / GPT-5"
|
||||
|
||||
msgid "Higher accuracy with variables, structured formats, and technical terminology."
|
||||
msgstr "Mayor precisión con variables, formatos estructurados y terminología técnica."
|
||||
|
||||
msgid "Long documents (100+ pages)"
|
||||
msgstr "Documentos largos (más de 100 páginas)"
|
||||
|
||||
msgid "Gemini 2.5 Pro"
|
||||
msgstr "Gemini 2.5 Pro"
|
||||
|
||||
msgid "1M token context window. Maintains terminological consistency across long texts."
|
||||
msgstr "Ventana de contexto de 1 millón de tokens. Mantiene la consistencia terminológica en textos extensos."
|
||||
|
||||
msgid "High volume / low cost"
|
||||
msgstr "Alto volumen / bajo coste"
|
||||
|
||||
msgid "DeepSeek-V3"
|
||||
msgstr "DeepSeek-V3"
|
||||
|
||||
msgid "Quality comparable to GPT-5 at ~$0.14/M tokens (20-50x cheaper than Claude/GPT)."
|
||||
msgstr "Calidad comparable a GPT-5 a ~0,14 $/M tokens (entre 20 y 50 veces más barato que Claude/GPT)."
|
||||
|
||||
msgid "Rare / indigenous languages"
|
||||
msgstr "Idiomas raros / indígenas"
|
||||
|
||||
msgid "Claude Sonnet or Taskade Translate (multi-model routing)"
|
||||
msgstr "Claude Sonnet o Taskade Translate (enrutado multimodelo)"
|
||||
|
||||
msgid "Better coverage for uncommon language pairs."
|
||||
msgstr "Mejor cobertura en pares de idiomas poco comunes."
|
||||
|
||||
msgid "Maximum coverage (133+ languages)"
|
||||
msgstr "Cobertura máxima (más de 133 idiomas)"
|
||||
|
||||
msgid "Google Cloud Translation"
|
||||
msgstr "Google Cloud Translation"
|
||||
|
||||
msgid "The most complete option, though with slightly lower quality on European languages."
|
||||
msgstr "La opción más completa, aunque con calidad ligeramente inferior en idiomas europeos."
|
||||
|
||||
msgid "The --locale flag is required."
|
||||
msgstr "El parámetro --locale es obligatorio."
|
||||
|
||||
msgid "The --post-id and --post-type flags are mutually exclusive."
|
||||
msgstr "Los parámetros --post-id y --post-type son mutuamente excluyentes."
|
||||
|
||||
msgid "No user context. Pass --user=<id|login> so post updates carry an author and capability checks apply."
|
||||
msgstr "Sin contexto de usuario. Pasa --user=<id|login> para que las actualizaciones de entradas tengan autor y se apliquen los controles de capacidades."
|
||||
|
||||
msgid "The WordPress AI plugin is not active."
|
||||
msgstr "El plugin WordPress AI no está activo."
|
||||
|
||||
msgid "The WordPress AI plugin has no provider configured for text generation."
|
||||
msgstr "El plugin WordPress AI no tiene ningún proveedor configurado para generación de texto."
|
||||
|
||||
#. translators: %s: locale code.
|
||||
#, php-format
|
||||
msgid "The locale %s is not installed on this site."
|
||||
msgstr "El idioma %s no está instalado en este sitio."
|
||||
|
||||
msgid "No translation fields are enabled in the plugin settings."
|
||||
msgstr "No hay ningún campo de traducción activado en los ajustes del plugin."
|
||||
|
||||
msgid "No posts matched the given criteria."
|
||||
msgstr "Ninguna entrada coincide con los criterios indicados."
|
||||
|
||||
#. translators: 1: success count, 2: failure count, 3: locale.
|
||||
#, php-format
|
||||
msgid "%1$d translated, %2$d failed (locale: %3$s)."
|
||||
msgstr "%1$d traducidas, %2$d con fallos (idioma: %3$s)."
|
||||
|
||||
msgid "Sorry, you are not allowed to edit this post."
|
||||
msgstr "Lo sentimos, no tienes permiso para editar esta entrada."
|
||||
|
||||
msgid "Post not found."
|
||||
msgstr "Entrada no encontrada."
|
||||
|
||||
msgid "The selected language is not installed on this site."
|
||||
msgstr "El idioma seleccionado no está instalado en este sitio."
|
||||
|
||||
msgid "No translatable fields were selected, or the requested fields are disabled in the settings."
|
||||
msgstr "No se ha seleccionado ningún campo traducible, o los campos solicitados están desactivados en los ajustes."
|
||||
|
||||
msgid "The WordPress AI plugin is not active. Translation is unavailable."
|
||||
msgstr "El plugin WordPress AI no está activo. La traducción no está disponible."
|
||||
|
||||
msgid "No translation fields are enabled in settings."
|
||||
msgstr "No hay ningún campo de traducción activado en los ajustes."
|
||||
|
||||
msgid "No languages are installed on this site."
|
||||
msgstr "No hay ningún idioma instalado en este sitio."
|
||||
|
||||
msgid "Target language"
|
||||
msgstr "Idioma de destino"
|
||||
|
||||
msgid "Translate"
|
||||
msgstr "Traducir"
|
||||
|
||||
msgid "Save the post before translating to ensure the latest content is used. The translation replaces the current title and/or content."
|
||||
msgstr "Guarda la entrada antes de traducir para que se use la versión más reciente. La traducción reemplaza el título y/o el contenido actuales."
|
||||
|
||||
msgid "Translating…"
|
||||
msgstr "Traduciendo…"
|
||||
|
||||
msgid "Translation applied. Review and save the post."
|
||||
msgstr "Traducción aplicada. Revisa y guarda la entrada."
|
||||
|
||||
msgid "Translation failed."
|
||||
msgstr "La traducción ha fallado."
|
||||
|
||||
msgid "You have unsaved changes. Save the post before translating to ensure the latest content is used."
|
||||
msgstr "Tienes cambios sin guardar. Guarda la entrada antes de traducir para que se use la versión más reciente."
|
||||
|
||||
msgid "The WordPress AI client is not available. Install and activate the WordPress AI plugin."
|
||||
msgstr "El cliente de WordPress AI no está disponible. Instala y activa el plugin WordPress AI."
|
||||
|
||||
msgid "The configured AI providers cannot serve text generation requests. Open the WordPress AI settings to configure a provider."
|
||||
msgstr "Los proveedores de IA configurados no pueden atender peticiones de generación de texto. Abre los ajustes de WordPress AI para configurar un proveedor."
|
||||
|
||||
msgid "The target language is not installed on this site."
|
||||
msgstr "El idioma de destino no está instalado en este sitio."
|
||||
|
||||
#. translators: %s: target language name.
|
||||
#, php-format
|
||||
msgid "You are a professional translator. Translate the user message into %s. Preserve any HTML, shortcodes, line breaks, and Markdown exactly as they appear. Return only the translated text, without explanations, prefaces, or quotation marks."
|
||||
msgstr "Eres un traductor profesional. Traduce el mensaje del usuario al %s. Preserva el HTML, los shortcodes, los saltos de línea y el Markdown exactamente como aparecen. Devuelve solo el texto traducido, sin explicaciones, prefacios ni comillas."
|
||||
|
||||
msgid "The AI service returned an unexpected response."
|
||||
msgstr "El servicio de IA ha devuelto una respuesta inesperada."
|
||||
|
||||
#. translators: %s: WordPress AI plugin link.
|
||||
#, php-format
|
||||
msgid "AI Translator (by ROBOTSTXT) requires the %s plugin to be active. Translation features will be disabled until it is installed and configured."
|
||||
msgstr "AI Translator (by ROBOTSTXT) necesita que el plugin %s esté activo. Las funciones de traducción estarán desactivadas hasta que se instale y configure."
|
||||
|
||||
msgid "WordPress AI"
|
||||
msgstr "WordPress AI"
|
||||
|
||||
msgid "Security check failed"
|
||||
msgstr "Comprobación de seguridad fallida"
|
||||
|
||||
msgid "You do not have sufficient permissions to access this page."
|
||||
msgstr "No tienes permisos suficientes para acceder a esta página."
|
||||
393
languages/robotstxt-ai-translator.pot
Normal file
393
languages/robotstxt-ai-translator.pot
Normal file
|
|
@ -0,0 +1,393 @@
|
|||
# Copyright (C) 2026 ROBOTSTXT
|
||||
# This file is distributed under the GPL-3.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: AI Translator (by ROBOTSTXT) 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/robotstxt-ai-translator\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-05-23T10:07:42+00:00\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"X-Generator: WP-CLI 2.12.0\n"
|
||||
"X-Domain: robotstxt-ai-translator\n"
|
||||
|
||||
#. Plugin Name of the plugin
|
||||
#: robotstxt-ai-translator.php
|
||||
msgid "AI Translator (by ROBOTSTXT)"
|
||||
msgstr ""
|
||||
|
||||
#. Plugin URI of the plugin
|
||||
#: robotstxt-ai-translator.php
|
||||
msgid "https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator"
|
||||
msgstr ""
|
||||
|
||||
#. Description of the plugin
|
||||
#: robotstxt-ai-translator.php
|
||||
msgid "Translate post titles and content from the editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration."
|
||||
msgstr ""
|
||||
|
||||
#. Author of the plugin
|
||||
#: robotstxt-ai-translator.php
|
||||
msgid "ROBOTSTXT"
|
||||
msgstr ""
|
||||
|
||||
#. Author URI of the plugin
|
||||
#: robotstxt-ai-translator.php
|
||||
msgid "https://www.robotstxt.es/"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:112
|
||||
#: includes/class-ai-translator-admin.php:113
|
||||
#: includes/class-ai-translator-admin.php:130
|
||||
#: includes/class-ai-translator-admin.php:131
|
||||
#: includes/class-ai-translator-editor-ui.php:282
|
||||
#: includes/class-ai-translator-editor-ui.php:433
|
||||
msgid "AI Translator"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:153
|
||||
#: includes/class-ai-translator-admin.php:171
|
||||
msgid "Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:187
|
||||
#: includes/class-ai-translator-admin.php:261
|
||||
msgid "You do not have permission to access this page."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:196
|
||||
msgid "AI Translator Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:200
|
||||
msgid "Settings saved."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:211
|
||||
#: includes/class-ai-translator-admin.php:214
|
||||
#: includes/class-ai-translator-admin.php:304
|
||||
#: includes/class-ai-translator-admin.php:308
|
||||
msgid "Translation fields"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:218
|
||||
#: includes/class-ai-translator-admin.php:312
|
||||
#: includes/class-ai-translator-editor-ui.php:440
|
||||
msgid "Translate title"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:223
|
||||
#: includes/class-ai-translator-admin.php:317
|
||||
#: includes/class-ai-translator-editor-ui.php:441
|
||||
msgid "Translate content"
|
||||
msgstr ""
|
||||
|
||||
#. translators: 1: title default, 2: content default.
|
||||
#: includes/class-ai-translator-admin.php:231
|
||||
#, php-format
|
||||
msgid "Network defaults: title %1$s, content %2$s."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:232
|
||||
#: includes/class-ai-translator-admin.php:233
|
||||
msgid "enabled"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:232
|
||||
#: includes/class-ai-translator-admin.php:233
|
||||
msgid "disabled"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:270
|
||||
msgid "AI Translator Network Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:274
|
||||
msgid "Network settings saved."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:284
|
||||
#: includes/class-ai-translator-admin.php:287
|
||||
msgid "Configuration mode"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:291
|
||||
msgid "Global configuration: a single setting applies to every site."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:296
|
||||
msgid "Per-site configuration: each site can override these defaults."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:321
|
||||
msgid "In global mode this is the configuration for the whole network. In per-site mode these values are used as defaults for sites that have not been configured individually."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:346
|
||||
#: includes/class-ai-translator-admin.php:378
|
||||
msgid "You do not have permission to perform this action."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:422
|
||||
msgid "Recommended models"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:425
|
||||
msgid "This plugin does not call AI providers directly. Configure your preferred provider in the WordPress AI plugin settings. The table below is a guide to help you pick a model based on your translation use case."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:431
|
||||
msgid "Use case"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:432
|
||||
msgid "Recommended model"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:433
|
||||
msgid "Why"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:448
|
||||
msgid "These recommendations are based on public benchmarks and community feedback as of the plugin release date. They may change as providers update their models."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:463
|
||||
msgid "European languages (ES, CA, FR, DE, IT, PT)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:464
|
||||
msgid "DeepL API Pro"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:465
|
||||
msgid "Best fluency and naturalness (92/100 in benchmarks). Formality control and custom glossaries."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:468
|
||||
msgid "Asian languages (ZH, JA, KO)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:469
|
||||
msgid "GPT-4o / GPT-5 or Claude Sonnet 4"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:470
|
||||
msgid "Better handling of implicit subjects, honorifics, and cultural references. DeepL falls behind here."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:473
|
||||
msgid "Marketing / brand tone"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:474
|
||||
msgid "Claude Sonnet 4 / Opus 4"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:475
|
||||
msgid "Better preservation of tone, brand voice, and nuance. Ideal for creative copy."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:478
|
||||
msgid "Technical documentation / code"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:479
|
||||
msgid "GPT-4o / GPT-5"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:480
|
||||
msgid "Higher accuracy with variables, structured formats, and technical terminology."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:483
|
||||
msgid "Long documents (100+ pages)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:484
|
||||
msgid "Gemini 2.5 Pro"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:485
|
||||
msgid "1M token context window. Maintains terminological consistency across long texts."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:488
|
||||
msgid "High volume / low cost"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:489
|
||||
msgid "DeepSeek-V3"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:490
|
||||
msgid "Quality comparable to GPT-5 at ~$0.14/M tokens (20-50x cheaper than Claude/GPT)."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:493
|
||||
msgid "Rare / indigenous languages"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:494
|
||||
msgid "Claude Sonnet or Taskade Translate (multi-model routing)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:495
|
||||
msgid "Better coverage for uncommon language pairs."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:498
|
||||
msgid "Maximum coverage (133+ languages)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:499
|
||||
msgid "Google Cloud Translation"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-admin.php:500
|
||||
msgid "The most complete option, though with slightly lower quality on European languages."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:120
|
||||
msgid "The --locale flag is required."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:124
|
||||
msgid "The --post-id and --post-type flags are mutually exclusive."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:129
|
||||
msgid "No user context. Pass --user=<id|login> so post updates carry an author and capability checks apply."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:133
|
||||
#: includes/class-ai-translator-editor-ui.php:438
|
||||
msgid "The WordPress AI plugin is not active."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:137
|
||||
msgid "The WordPress AI plugin has no provider configured for text generation."
|
||||
msgstr ""
|
||||
|
||||
#. translators: %s: locale code.
|
||||
#: includes/class-ai-translator-cli.php:144
|
||||
#, php-format
|
||||
msgid "The locale %s is not installed on this site."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:153
|
||||
msgid "No translation fields are enabled in the plugin settings."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-cli.php:179
|
||||
msgid "No posts matched the given criteria."
|
||||
msgstr ""
|
||||
|
||||
#. translators: 1: success count, 2: failure count, 3: locale.
|
||||
#: includes/class-ai-translator-cli.php:230
|
||||
#, php-format
|
||||
msgid "%1$d translated, %2$d failed (locale: %3$s)."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:160
|
||||
msgid "Sorry, you are not allowed to edit this post."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:190
|
||||
msgid "Post not found."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:199
|
||||
msgid "The selected language is not installed on this site."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:217
|
||||
msgid "No translatable fields were selected, or the requested fields are disabled in the settings."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:307
|
||||
msgid "The WordPress AI plugin is not active. Translation is unavailable."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:309
|
||||
#: includes/class-ai-translator-editor-ui.php:437
|
||||
msgid "No translation fields are enabled in settings."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:311
|
||||
#: includes/class-ai-translator-editor-ui.php:436
|
||||
msgid "No languages are installed on this site."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:314
|
||||
#: includes/class-ai-translator-editor-ui.php:432
|
||||
msgid "Target language"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:324
|
||||
#: includes/class-ai-translator-editor-ui.php:430
|
||||
msgid "Translate"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:329
|
||||
msgid "Save the post before translating to ensure the latest content is used. The translation replaces the current title and/or content."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:431
|
||||
msgid "Translating…"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:434
|
||||
msgid "Translation applied. Review and save the post."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:435
|
||||
msgid "Translation failed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-editor-ui.php:439
|
||||
msgid "You have unsaved changes. Save the post before translating to ensure the latest content is used."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-translator.php:82
|
||||
msgid "The WordPress AI client is not available. Install and activate the WordPress AI plugin."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-translator.php:89
|
||||
msgid "The configured AI providers cannot serve text generation requests. Open the WordPress AI settings to configure a provider."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-translator.php:98
|
||||
msgid "The target language is not installed on this site."
|
||||
msgstr ""
|
||||
|
||||
#. translators: %s: target language name.
|
||||
#: includes/class-ai-translator-translator.php:104
|
||||
#, php-format
|
||||
msgid "You are a professional translator. Translate the user message into %s. Preserve any HTML, shortcodes, line breaks, and Markdown exactly as they appear. Return only the translated text, without explanations, prefaces, or quotation marks."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-ai-translator-translator.php:125
|
||||
msgid "The AI service returned an unexpected response."
|
||||
msgstr ""
|
||||
|
||||
#. translators: %s: WordPress AI plugin link.
|
||||
#: robotstxt-ai-translator.php:109
|
||||
#, php-format
|
||||
msgid "AI Translator (by ROBOTSTXT) requires the %s plugin to be active. Translation features will be disabled until it is installed and configured."
|
||||
msgstr ""
|
||||
|
||||
#: robotstxt-ai-translator.php:110
|
||||
msgid "WordPress AI"
|
||||
msgstr ""
|
||||
|
||||
#: robotstxt-updater.php:362
|
||||
msgid "Security check failed"
|
||||
msgstr ""
|
||||
|
||||
#: robotstxt-updater.php:367
|
||||
msgid "You do not have sufficient permissions to access this page."
|
||||
msgstr ""
|
||||
160
readme.txt
Normal file
160
readme.txt
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
=== AI Translator (by ROBOTSTXT) ===
|
||||
Contributors: robotstxt, javiercasares
|
||||
Tags: ai, translation, multilingual, multisite, editor
|
||||
Requires at least: 7.0
|
||||
Tested up to: 7.0
|
||||
Requires PHP: 7.4
|
||||
Requires Plugins: ai
|
||||
Stable tag: 1.0.0
|
||||
License: GPL-3.0-or-later
|
||||
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
|
||||
Translate post titles and content from the WordPress editor using the native WordPress AI plugin as backend. Multisite-ready.
|
||||
|
||||
== Description ==
|
||||
|
||||
AI Translator (by ROBOTSTXT) adds a one-click translation panel to the post editor. It reads the saved post title and content, sends them to the configured AI provider through the official WordPress AI plugin, and writes the translated text back into the editor for review.
|
||||
|
||||
The plugin is provider-agnostic: it relies on the WordPress AI plugin to route requests to whichever service the site administrator has configured (OpenAI, Anthropic, Google, etc.). No API keys are stored by this plugin.
|
||||
|
||||
Multisite is supported out of the box. When network-activated, the network administrator chooses between a single global configuration shared by every site, or per-site configuration where each subsite owns its own settings.
|
||||
|
||||
== Using the plugin ==
|
||||
|
||||
= Editor =
|
||||
|
||||
On the post edit screen, open the "AI Translator" panel (block editor sidebar or classic editor metabox). Select a target language from the dropdown and click "Translate". The plugin reads the saved version of the post, calls the configured AI provider, and replaces the title and/or content with the translated values. Review the result and save the post.
|
||||
|
||||
Only languages installed on the site (via Settings -> General -> Site Language, or the language pack installer) appear in the dropdown.
|
||||
|
||||
= WP-CLI =
|
||||
|
||||
The plugin exposes a single command, `wp ai-translator translate`, for single-post and bulk translation.
|
||||
|
||||
**Flags**
|
||||
|
||||
* `--locale=<locale>` (required): WordPress locale code to translate to. The locale must be installed on the site (visible via `wp language core list --status=installed`). The built-in `en_US` is always available.
|
||||
* `--post-id=<id>` (optional): ID of a single post to translate. When set, `--post-type`, `--status` and `--limit` are ignored.
|
||||
* `--post-type=<type>` (optional, default `post`): Post type to translate in bulk when `--post-id` is not provided.
|
||||
* `--status=<status>` (optional, default `publish`): Post status filter in bulk mode.
|
||||
* `--limit=<n>` (optional, default `50`): Maximum number of posts to process in bulk mode.
|
||||
* `--dry-run` (optional): Report which posts would be translated **without calling the AI provider and without writing to the database**. Useful for previewing scope and verifying filters before incurring API costs.
|
||||
|
||||
The command respects the plugin's site settings (`Translate title` / `Translate content`). If both are disabled in the settings, the command exits with an error.
|
||||
|
||||
**Multisite**
|
||||
|
||||
Use the standard `--url=<site-url>` and `--path=<wordpress-root>` flags from WP-CLI to target a specific site in the network.
|
||||
|
||||
**User context**
|
||||
|
||||
Pass the standard WP-CLI global flag `--user=<id|login>` so that post updates are recorded under that user (revisions, audit logs). The command emits a warning when no user context is set.
|
||||
|
||||
**Examples**
|
||||
|
||||
Translate a single post to Spanish:
|
||||
|
||||
`wp ai-translator translate --post-id=42 --locale=es_ES`
|
||||
|
||||
Translate the latest ten pages to French, preview only:
|
||||
|
||||
`wp ai-translator translate --post-type=page --locale=fr_FR --limit=10 --dry-run`
|
||||
|
||||
Translate up to 200 product custom post types to Catalan on a Multisite subsite:
|
||||
|
||||
`wp ai-translator translate --post-type=product --locale=ca --limit=200 --url=https://example.com/ca/`
|
||||
|
||||
Bulk translate all draft posts (use with caution):
|
||||
|
||||
`wp ai-translator translate --post-type=post --status=draft --locale=de_DE --limit=500`
|
||||
|
||||
= REST API =
|
||||
|
||||
The plugin registers a single REST route in the `ai-translator/v1` namespace:
|
||||
|
||||
`POST /wp-json/ai-translator/v1/translate`
|
||||
|
||||
**Authentication**
|
||||
|
||||
Requires authenticated access to WordPress (cookie + `X-WP-Nonce` header for in-browser use, or Application Passwords for external clients) and the `edit_post` capability on the target post. Unauthorised requests receive `401` or `403` per `rest_authorization_required_code()`.
|
||||
|
||||
**Request body** (JSON)
|
||||
|
||||
* `post_id` (integer, required): ID of an existing post.
|
||||
* `fields` (array of strings, required): Which fields to translate. Allowed values: `"title"`, `"content"`. Empty array or fields disabled in settings yield a `400`.
|
||||
* `target_locale` (string, required): WordPress locale code. Must be installed on the site.
|
||||
|
||||
**Response** (200 OK, JSON)
|
||||
|
||||
Only includes the keys that were actually translated:
|
||||
|
||||
`{ "title": "...", "content": "..." }`
|
||||
|
||||
**Errors**
|
||||
|
||||
* `400` invalid input (missing post, unknown locale, no enabled fields).
|
||||
* `403` insufficient capability.
|
||||
* `404` post not found.
|
||||
* `502` upstream AI provider error (forwarded from the WordPress AI plugin).
|
||||
|
||||
**Important**
|
||||
|
||||
The endpoint reads the **saved** title and content from the database, not from the editor's current state. Save the post before translating to ensure the latest content is used.
|
||||
|
||||
== Extra Configurations ==
|
||||
|
||||
`AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL` (boolean, default false): when set to `true` in wp-config.php, the uninstall routine removes every option, sitemeta entry, and per-site setting created by the plugin. By default, plugin data is preserved on uninstall.
|
||||
|
||||
== Installation ==
|
||||
|
||||
= Requirements =
|
||||
|
||||
* WordPress 7.0 or higher.
|
||||
* PHP 7.4 or higher.
|
||||
* The official WordPress AI plugin (https://wordpress.org/plugins/ai/) installed, active, and configured with valid provider credentials.
|
||||
|
||||
= Manual download =
|
||||
|
||||
Extract the contents of the ZIP and upload the contents to the `/wp-content/plugins/robotstxt-ai-translator/` directory. Once uploaded, it will appear in your plugin list.
|
||||
|
||||
On Multisite, network-activate the plugin and configure it under Network Admin -> Settings -> AI Translator.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Does this plugin call any AI provider directly? =
|
||||
|
||||
No. Every AI request is delegated to the official WordPress AI plugin, which handles authentication, model selection, and provider routing. This plugin does not store API keys.
|
||||
|
||||
= Does it work with the classic editor? =
|
||||
|
||||
Yes. The plugin registers a metabox in the classic editor and a sidebar panel in the block editor. Both share the same REST endpoint and language list.
|
||||
|
||||
= Why do I have to save the post before translating? =
|
||||
|
||||
The plugin reads the post title and content from the database, not from the editor's current state. This prevents prompt-injection through unsaved editor content. The UI warns you when there are unsaved changes.
|
||||
|
||||
== Compatibility ==
|
||||
|
||||
* WordPress: 7.0
|
||||
* PHP: 7.4 - 8.5
|
||||
* WP-CLI: 2.10 or newer
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.0.0 =
|
||||
|
||||
* Initial release. Translation panel for block and classic editors, REST endpoint, WP-CLI command, single-site and Multisite (global / per-site) configuration modes.
|
||||
|
||||
= Previous versions =
|
||||
|
||||
If you want to see the full changelog, visit the [changelog.txt](https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator/raw/branch/main/changelog.txt) file.
|
||||
|
||||
== Compliance ==
|
||||
|
||||
This plugin adheres to the following security measures and review protocols for each version:
|
||||
|
||||
* [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
|
||||
* [WordPress Plugin Security](https://developer.wordpress.org/plugins/wordpress-org/plugin-security/)
|
||||
* [WordPress APIs Security](https://developer.wordpress.org/apis/security/)
|
||||
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
|
||||
* [Plugin Check (PCP)](https://wordpress.org/plugins/plugin-check/)
|
||||
147
robotstxt-ai-translator.php
Normal file
147
robotstxt-ai-translator.php
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: AI Translator (by ROBOTSTXT)
|
||||
* Plugin URI: https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator
|
||||
* Gitea Plugin URI: ROBOTSTXT/robotstxt-ai-translator
|
||||
* Description: Translate post titles and content from the editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration.
|
||||
* Version: 1.0.0
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.es/
|
||||
* License: GPL-3.0-or-later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
* Text Domain: robotstxt-ai-translator
|
||||
* Domain Path: /languages
|
||||
* Requires at least: 7.0
|
||||
* Requires PHP: 7.4
|
||||
* Requires Plugins: ai
|
||||
* Network: true
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin version.
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_VERSION', '1.0.0' );
|
||||
|
||||
/**
|
||||
* Main plugin file path.
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_FILE', __FILE__ );
|
||||
|
||||
/**
|
||||
* Plugin directory path (with trailing slash).
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_DIR', plugin_dir_path( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* Plugin URL (with trailing slash).
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* Plugin basename (e.g. robotstxt-ai-translator/robotstxt-ai-translator.php).
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_BASENAME', plugin_basename( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* REST API namespace.
|
||||
*/
|
||||
define( 'AI_TRANSLATOR_REST_NAMESPACE', 'ai-translator/v1' );
|
||||
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-settings.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-translator.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-admin.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-editor-ui.php';
|
||||
require_once AI_TRANSLATOR_DIR . 'robotstxt-updater.php';
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
require_once AI_TRANSLATOR_DIR . 'includes/class-ai-translator-cli.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the plugin text domain.
|
||||
*
|
||||
* Hooked on `init` per WordPress 6.7+ guidance (loading earlier triggers a
|
||||
* `_load_textdomain_just_in_time` deprecation notice).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ai_translator_load_textdomain() {
|
||||
load_plugin_textdomain(
|
||||
'robotstxt-ai-translator',
|
||||
false,
|
||||
dirname( AI_TRANSLATOR_BASENAME ) . '/languages'
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'ai_translator_load_textdomain' );
|
||||
|
||||
/**
|
||||
* Bootstraps the plugin once all plugins are loaded.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ai_translator_bootstrap() {
|
||||
$settings = new AI_Translator_Settings();
|
||||
$translator = new AI_Translator_Translator();
|
||||
$admin = new AI_Translator_Admin( $settings );
|
||||
$editor_ui = new AI_Translator_Editor_UI( $settings, $translator );
|
||||
|
||||
$admin->register();
|
||||
$editor_ui->register();
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
$cli = new AI_Translator_CLI( $settings, $translator );
|
||||
$cli->register();
|
||||
}
|
||||
|
||||
Robotstxt_Updater::init( AI_TRANSLATOR_FILE );
|
||||
}
|
||||
add_action( 'plugins_loaded', 'ai_translator_bootstrap' );
|
||||
|
||||
/**
|
||||
* Renders an admin notice when the WordPress AI plugin is not active.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ai_translator_dependency_notice() {
|
||||
if ( function_exists( 'wp_ai_client_prompt' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'activate_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
/* translators: %s: WordPress AI plugin link. */
|
||||
esc_html__( 'AI Translator (by ROBOTSTXT) requires the %s plugin to be active. Translation features will be disabled until it is installed and configured.', 'robotstxt-ai-translator' ),
|
||||
'<a href="https://wordpress.org/plugins/ai/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'WordPress AI', 'robotstxt-ai-translator' ) . '</a>'
|
||||
);
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-warning"><p>%s</p></div>',
|
||||
wp_kses(
|
||||
$message,
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'ai_translator_dependency_notice' );
|
||||
add_action( 'network_admin_notices', 'ai_translator_dependency_notice' );
|
||||
383
robotstxt-updater.php
Normal file
383
robotstxt-updater.php
Normal file
|
|
@ -0,0 +1,383 @@
|
|||
<?php
|
||||
/**
|
||||
* Generic JSON-based updater for ROBOTSTXT plugins.
|
||||
*
|
||||
* This file is designed to be copied to any ROBOTSTXT plugin.
|
||||
* It auto-configures itself by reading the plugin headers.
|
||||
*
|
||||
* @package ROBOTSTXT
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Robotstxt_Updater' ) ) {
|
||||
/**
|
||||
* Class Robotstxt_Updater
|
||||
*
|
||||
* Generic updater that works with any plugin.
|
||||
* Reads plugin headers and constructs update URL automatically.
|
||||
*/
|
||||
class Robotstxt_Updater {
|
||||
|
||||
/**
|
||||
* Plugin file path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_file_path;
|
||||
|
||||
/**
|
||||
* Plugin basename (e.g., 'my-plugin/my-plugin.php').
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_basename;
|
||||
|
||||
/**
|
||||
* Plugin slug (directory name).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_slug;
|
||||
|
||||
/**
|
||||
* Remote JSON URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $json_url;
|
||||
|
||||
/**
|
||||
* Cache key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $cache_key;
|
||||
|
||||
/**
|
||||
* Plugin headers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $plugin_data;
|
||||
|
||||
/**
|
||||
* Initialize the updater.
|
||||
*
|
||||
* Usage in your main plugin file:
|
||||
* require_once __DIR__ . '/robotstxt-updater.php';
|
||||
* Robotstxt_Updater::init( __FILE__ );
|
||||
*
|
||||
* @param string $plugin_file_path Absolute path to the main plugin file.
|
||||
*/
|
||||
public static function init( string $plugin_file_path ): void {
|
||||
$instance = new self( $plugin_file_path );
|
||||
$instance->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $plugin_file_path Absolute path to the main plugin file.
|
||||
*/
|
||||
private function __construct( string $plugin_file_path ) {
|
||||
$this->plugin_file_path = $plugin_file_path;
|
||||
$this->plugin_basename = plugin_basename( $plugin_file_path );
|
||||
$this->plugin_slug = dirname( $this->plugin_basename );
|
||||
$this->plugin_data = $this->get_plugin_data();
|
||||
$this->json_url = $this->build_json_url();
|
||||
$this->cache_key = 'robotstxt_updater_' . md5( $this->plugin_basename );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register WordPress hooks.
|
||||
*/
|
||||
private function register(): void {
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'inject_update_info' ) );
|
||||
add_filter( 'plugins_api', array( $this, 'provide_plugin_details' ), 10, 3 );
|
||||
add_action( 'admin_init', array( $this, 'handle_cache_clear' ) );
|
||||
add_action( 'robotstxt_updater_clear_cache', array( $this, 'clear_cache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin headers.
|
||||
*
|
||||
* @return array Plugin data.
|
||||
*/
|
||||
private function get_plugin_data(): array {
|
||||
if ( ! function_exists( 'get_plugin_data' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
return get_plugin_data( $this->plugin_file_path, false, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build JSON URL from plugin headers.
|
||||
*
|
||||
* Tries to use "Gitea Plugin URI" header to construct the URL.
|
||||
* Falls back to Plugin URI if Gitea URI is not available.
|
||||
*
|
||||
* @return string JSON URL.
|
||||
*/
|
||||
private function build_json_url(): string {
|
||||
// Try Gitea Plugin URI (format: "OWNER/REPO" or full URL).
|
||||
if ( ! empty( $this->plugin_data['Gitea Plugin URI'] ) ) {
|
||||
$gitea_uri = $this->plugin_data['Gitea Plugin URI'];
|
||||
|
||||
// If it's already a full URL, use it.
|
||||
if ( str_starts_with( $gitea_uri, 'http' ) ) {
|
||||
// Extract base URL and construct JSON path.
|
||||
return rtrim( $gitea_uri, '/' ) . '/raw/branch/main/update.json';
|
||||
}
|
||||
|
||||
// If it's in format "OWNER/REPO", construct full URL.
|
||||
if ( preg_match( '#^[^/]+/[^/]+$#', $gitea_uri ) ) {
|
||||
return "https://git.robotstxt.es/{$gitea_uri}/raw/branch/main/update.json";
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try to extract from Plugin URI.
|
||||
if ( ! empty( $this->plugin_data['PluginURI'] ) ) {
|
||||
$plugin_uri = $this->plugin_data['PluginURI'];
|
||||
if ( str_contains( $plugin_uri, 'git.robotstxt.es' ) ) {
|
||||
return rtrim( $plugin_uri, '/' ) . '/raw/branch/main/update.json';
|
||||
}
|
||||
}
|
||||
|
||||
// Last resort: construct from plugin slug.
|
||||
return "https://git.robotstxt.es/ROBOTSTXT/{$this->plugin_slug}/raw/branch/main/update.json";
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject update info into WP's plugin update transient.
|
||||
*
|
||||
* @param object|mixed $transient The update_plugins transient.
|
||||
*
|
||||
* @return object The modified transient.
|
||||
*/
|
||||
public function inject_update_info( $transient ) {
|
||||
if ( ! is_object( $transient ) ) {
|
||||
$transient = new stdClass();
|
||||
}
|
||||
|
||||
if ( empty( $transient->checked ) || ! is_array( $transient->checked ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if ( empty( $transient->checked[ $this->plugin_basename ] ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
$current_version = $transient->checked[ $this->plugin_basename ];
|
||||
$remote = $this->get_remote_data();
|
||||
|
||||
if ( empty( $remote['version'] ) || empty( $remote['download_url'] ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if ( ! $this->is_compatible( $remote ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if ( version_compare( $remote['version'], $current_version, '>' ) ) {
|
||||
$update = (object) array(
|
||||
'slug' => $remote['slug'] ?? $this->plugin_slug,
|
||||
'plugin' => $this->plugin_basename,
|
||||
'new_version' => $remote['version'],
|
||||
'url' => $remote['homepage'] ?? $this->plugin_data['PluginURI'] ?? '',
|
||||
'package' => $remote['download_url'],
|
||||
'tested' => $remote['tested'] ?? '',
|
||||
'requires' => $remote['requires'] ?? '',
|
||||
'requires_php' => $remote['requires_php'] ?? '',
|
||||
);
|
||||
|
||||
$transient->response[ $this->plugin_basename ] = $update;
|
||||
}
|
||||
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide "View details" modal content.
|
||||
*
|
||||
* @param false|object|array $result The result object or array.
|
||||
* @param string $action The type of information being requested.
|
||||
* @param object $args Plugin API arguments.
|
||||
*
|
||||
* @return false|object The plugin information object or false.
|
||||
*/
|
||||
public function provide_plugin_details( $result, string $action, object $args ) {
|
||||
if ( 'plugin_information' !== $action ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( empty( $args->slug ) || $args->slug !== $this->plugin_slug ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$remote = $this->get_remote_data();
|
||||
|
||||
if ( empty( $remote['version'] ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return (object) array(
|
||||
'name' => $remote['name'] ?? $this->plugin_data['Name'] ?? $this->plugin_slug,
|
||||
'slug' => $remote['slug'] ?? $this->plugin_slug,
|
||||
'version' => $remote['version'],
|
||||
'author' => $remote['author'] ?? $this->plugin_data['Author'] ?? '',
|
||||
'homepage' => $remote['homepage'] ?? $this->plugin_data['PluginURI'] ?? '',
|
||||
'requires' => $remote['requires'] ?? '',
|
||||
'tested' => $remote['tested'] ?? '',
|
||||
'requires_php' => $remote['requires_php'] ?? '',
|
||||
'sections' => array(
|
||||
'description' => $remote['description'] ?? $this->plugin_data['Description'] ?? '',
|
||||
'changelog' => $remote['changelog'] ?? '',
|
||||
),
|
||||
'download_link' => $remote['download_url'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remote data with caching and HMAC signature verification.
|
||||
*
|
||||
* @return array Remote data.
|
||||
*/
|
||||
private function get_remote_data(): array {
|
||||
$cached = get_site_transient( $this->cache_key );
|
||||
|
||||
// Verify HMAC signature if AUTH_SALT is defined and cache has signature.
|
||||
if ( false !== $cached && defined( 'AUTH_SALT' ) && '' !== AUTH_SALT ) {
|
||||
if ( is_array( $cached ) && isset( $cached['signature'], $cached['data'] ) ) {
|
||||
$expected_sig = hash_hmac( 'sha256', $this->cache_key . serialize( $cached['data'] ), AUTH_SALT );
|
||||
|
||||
if ( hash_equals( $expected_sig, $cached['signature'] ) ) {
|
||||
// Signature valid, return data.
|
||||
return is_array( $cached['data'] ) ? $cached['data'] : array();
|
||||
}
|
||||
|
||||
// Signature invalid, delete corrupted cache.
|
||||
delete_site_transient( $this->cache_key );
|
||||
$cached = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If no valid cache, fetch fresh data.
|
||||
if ( false === $cached ) {
|
||||
$remote = $this->fetch_json();
|
||||
|
||||
// Store with HMAC signature if AUTH_SALT is available.
|
||||
if ( defined( 'AUTH_SALT' ) && '' !== AUTH_SALT ) {
|
||||
$payload = array(
|
||||
'data' => $remote ?: array(),
|
||||
'timestamp' => time(),
|
||||
'signature' => hash_hmac( 'sha256', $this->cache_key . serialize( $remote ?: array() ), AUTH_SALT ),
|
||||
);
|
||||
set_site_transient( $this->cache_key, $payload, 6 * HOUR_IN_SECONDS );
|
||||
} else {
|
||||
// Fallback to standard caching.
|
||||
set_site_transient( $this->cache_key, $remote ?: array(), 6 * HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return is_array( $remote ) ? $remote : array();
|
||||
}
|
||||
|
||||
// Legacy cache format without signature (backward compatibility).
|
||||
return is_array( $cached ) ? $cached : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch JSON from remote URL.
|
||||
*
|
||||
* @return array Decoded JSON data.
|
||||
*/
|
||||
private function fetch_json(): array {
|
||||
$response = wp_remote_get(
|
||||
$this->json_url,
|
||||
array(
|
||||
'timeout' => 10,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( $code < 200 || $code >= 300 ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$data = json_decode( $body, true );
|
||||
|
||||
return is_array( $data ) ? $data : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check compatibility.
|
||||
*
|
||||
* @param array $remote Remote data.
|
||||
*
|
||||
* @return bool True if compatible.
|
||||
*/
|
||||
private function is_compatible( array $remote ): bool {
|
||||
if ( ! empty( $remote['requires_php'] ) ) {
|
||||
if ( version_compare( PHP_VERSION, $remote['requires_php'], '<' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $remote['requires'] ) ) {
|
||||
if ( version_compare( get_bloginfo( 'version' ), $remote['requires'], '<' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle manual cache clear via URL parameter.
|
||||
*/
|
||||
public function handle_cache_clear(): void {
|
||||
// Check if this is a cache clear request first.
|
||||
$clear_cache = filter_input( INPUT_GET, 'robotstxt_clear_update_cache', FILTER_UNSAFE_RAW );
|
||||
if ( null === $clear_cache ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This is a cache clear request - now verify nonce.
|
||||
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_UNSAFE_RAW );
|
||||
$nonce = $nonce_raw ? sanitize_text_field( wp_unslash( $nonce_raw ) ) : '';
|
||||
|
||||
if ( ! wp_verify_nonce( $nonce, 'robotstxt_clear_update_cache' ) ) {
|
||||
wp_die( esc_html__( 'Security check failed', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
// Check permissions.
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
$this->clear_cache();
|
||||
wp_safe_redirect( remove_query_arg( array( 'robotstxt_clear_update_cache', '_wpnonce' ) ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear update cache.
|
||||
*/
|
||||
public function clear_cache(): void {
|
||||
delete_site_transient( $this->cache_key );
|
||||
delete_site_transient( 'update_plugins' );
|
||||
}
|
||||
}
|
||||
}
|
||||
50
uninstall.php
Normal file
50
uninstall.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* Uninstall handler for the AI Translator plugin.
|
||||
*
|
||||
* Plugin data is preserved by default. To delete every option and sitemeta entry,
|
||||
* either set the constant AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL to true in wp-config.php,
|
||||
* or define the site option 'ai_translator_delete_data_on_uninstall' as a truthy value.
|
||||
*
|
||||
* @package ROBOTSTXT\AI_Translator
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$ai_translator_should_delete = false;
|
||||
|
||||
if ( defined( 'AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL' ) && AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL ) {
|
||||
$ai_translator_should_delete = true;
|
||||
}
|
||||
|
||||
if ( ! $ai_translator_should_delete && function_exists( 'get_site_option' ) ) {
|
||||
$ai_translator_should_delete = (bool) get_site_option( 'ai_translator_delete_data_on_uninstall', false );
|
||||
}
|
||||
|
||||
if ( ! $ai_translator_should_delete ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$ai_translator_sites = get_sites(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
'number' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $ai_translator_sites as $ai_translator_site_id ) {
|
||||
switch_to_blog( (int) $ai_translator_site_id );
|
||||
delete_option( 'ai_translator_settings' );
|
||||
restore_current_blog();
|
||||
}
|
||||
|
||||
delete_site_option( 'ai_translator_settings' );
|
||||
delete_site_option( 'ai_translator_network_mode' );
|
||||
delete_site_option( 'ai_translator_delete_data_on_uninstall' );
|
||||
} else {
|
||||
delete_option( 'ai_translator_settings' );
|
||||
}
|
||||
27
update.json
Normal file
27
update.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "AI Translator (by ROBOTSTXT)",
|
||||
"slug": "robotstxt-ai-translator",
|
||||
"version": "1.0.0",
|
||||
"download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator/releases/download/1.0.0/robotstxt-ai-translator-1.0.0.zip",
|
||||
"requires": "7.0",
|
||||
"requires_php": "7.4",
|
||||
"tested": "7.0",
|
||||
"last_updated": "2026-05-23",
|
||||
"author": "ROBOTSTXT",
|
||||
"author_profile": "https://www.robotstxt.es/",
|
||||
"homepage": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-ai-translator",
|
||||
"description": "Translate post titles and content from the WordPress editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration.",
|
||||
"changelog": "<h3>1.0.0 - 2026-05-23</h3><ul><li><strong>Added:</strong> Block editor sidebar and Classic editor metabox with language selector and Translate button.</li><li><strong>Added:</strong> REST endpoint POST /wp-json/ai-translator/v1/translate.</li><li><strong>Added:</strong> WP-CLI command wp ai-translator translate for single-post and bulk translation.</li><li><strong>Added:</strong> Network admin settings page with global / per-site configuration mode.</li><li><strong>Added:</strong> Site admin settings page with title and content translation toggles.</li><li><strong>Added:</strong> Model recommendations table in the settings pages.</li></ul>",
|
||||
"sections": {
|
||||
"description": "Translate post titles and content from the WordPress editor using the native WordPress AI plugin as backend. Multisite-ready with global or per-site configuration.",
|
||||
"changelog": "<h3>1.0.0 - 2026-05-23</h3><ul><li><strong>Added:</strong> Block editor sidebar and Classic editor metabox with language selector and Translate button.</li><li><strong>Added:</strong> REST endpoint POST /wp-json/ai-translator/v1/translate.</li><li><strong>Added:</strong> WP-CLI command wp ai-translator translate for single-post and bulk translation.</li><li><strong>Added:</strong> Network admin settings page with global / per-site configuration mode.</li><li><strong>Added:</strong> Site admin settings page with title and content translation toggles.</li><li><strong>Added:</strong> Model recommendations table in the settings pages.</li></ul>"
|
||||
},
|
||||
"banners": {
|
||||
"low": "",
|
||||
"high": ""
|
||||
},
|
||||
"icons": {
|
||||
"1x": "",
|
||||
"2x": ""
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue