I do not think that AI tools are used in the way you anticipate (to create 'translations' for the purpose to avoid copyright implications). AI learning usually happens by consuming code or language or pictures and extracting patterns and characteristics of that original source without saving a copy of that source. Due to the fact that the original sources are not stored by the AI, outputs are created by applying the patterns and characteristics of many sources, and therefore these outputs are not considered a derivative work of any specific input file.
The underlying legal concept for open source licenses is copyright. The owners of copyright in the code decide what may or may not be done with the code. Any permissions and restrictions by an OSS license can only cover the areas that would otherwise be forbidden under copyright law in the absence of a license.
What does copyright law say?
Europe: DSM Directive
Article 4: Exception or limitation for text and data mining
Member States shall provide for an exception or limitation to the rights provided for in Article 5(a) and Article 7(1) of Directive
96/9/EC, Article 2 of Directive 2001/29/EC, Article 4(1)(a) and (b) of
Directive 2009/24/EC and Article 15(1) of this Directive for
reproductions and extractions of lawfully accessible works and other
subject matter for the purposes of text and data mining.
Reproductions and extractions made pursuant to paragraph 1 may be retained for as long as is necessary for the purposes of text and data
The exception or limitation provided for in paragraph 1 shall apply on condition that the use of works and other subject matter
referred to in that paragraph has not been expressly reserved by their
rightholders in an appropriate manner, such as machine-readable means
in the case of content made publicly available online.
In summary this means that in Europe publicly accessible content is free to use for AI-learning unless there is a machine-readable ban on the website.
Collecting data from 3rd party websites (so-called screen scraping) is legal but the Supreme Court still has to decide on some AI specific cases
Now what is allowed by the open source licenses? Here a few examples:
MIT License gives a broad blank check for any use. I don't see how AI learning would be excluded "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software ..."
2-clause BSD License provides a very broad license "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ..." where the word 'use' can easily be interpreted to allow the use as input for AI learning.
Apache2 License "Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form." The Apache license does not seem to specifically allow or disallow the use of code for AI learning.
GPLv3 is very specific "You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force." The term 'propagate' in this sentence has a very wide definition: "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." I think that would include AI learning. In addition, Section 7 of the GPLv3 license limits the types of restrictions that may be applied.
OSS licenses have been written at times when AI and ML were far away. Would it be possible to add an anti-AI-learning clause to OSS licenses?
If you are the sole copyright holder of code you may set up any license with any restriction, but this would no longer be the MIT license or the BSD license, and others would often refrain from re-using your code due to the fact that it is a crayon license (How can a "crayon" license be a problem?).
Existing code (with other copyright holders) cannot easily be re-licensed unless you have the consent of every copyright holder. GPL licensed code more or less excludes any such restrictions.
Is there an SPDX indicator or any other agreed way to disagree with AI-learning?
I am not aware if specific SPDX ID that would be a machine-readable bar against AI, but there is a SPDX community talking about AI.
robots.txt : You can prevent crawlers from searching your own website, and if the AI engine is friendly it will respect your wish. Obviously that will only work for your own website where you control the robots.txt and would not work for 3rd party websites where code is shared (such as GitHub).
website T&Cs: same as robots.txt
GitHub T&Cs: GitHub is owned by Microsoft, and offers its own AI solution for code, Github Copilot. Therefore GitHub has T&Cs which allow for sharing, and you agree to these before you upload any code. In Section D.4 'License Grant to Us' you can find the words "This license includes the right to do things like copy it to our database and make backups; show it to you and other users; parse it into a search index or otherwise analyze it on our servers;..." which sounds like a blank check for AI learning.
So in summary: Yes, you can protect your own code from being used in AI-learning, but current developments in copyright law, the lack of specific OSS licenses for that purpose, and the T&Cs of code sharing websites such as GitHub make it incredibly difficult for you.